Skip to content

Commit 14e8bde

Browse files
committed
♻️ Refactor tests
1 parent 02fa9ad commit 14e8bde

File tree

87 files changed

+6949
-18
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+6949
-18
lines changed

phpunit.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99
processIsolation="false"
1010
stopOnFailure="false">
1111
<testsuites>
12-
<testsuite name="Tests">
13-
<directory suffix="Test.php">./tests</directory>
12+
<testsuite name="Commands">
13+
<directory suffix="Test.php">./tests/Commands</directory>
14+
</testsuite>
15+
<testsuite name="Recipes">
16+
<directory suffix="Test.php">./tests/Recipes</directory>
17+
</testsuite>
18+
<testsuite name="Unit">
19+
<directory suffix="Test.php">./tests/Unit</directory>
1420
</testsuite>
1521
</testsuites>
1622
</phpunit>

tests/DeployListTest.php renamed to tests/Commands/DeployListTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace Lorisleiva\LaravelDeployer\Test;
3+
namespace Lorisleiva\LaravelDeployer\Test\Commands;
44

5-
use Illuminate\Console\Application;
6-
use Illuminate\Support\Facades\Artisan;
5+
use Lorisleiva\LaravelDeployer\Test\DeploymentTestCase;
6+
use Lorisleiva\LaravelDeployer\Test\TestCase;
77

8-
class DeployListTest extends TestCase
8+
class DeployListTest extends DeploymentTestCase
99
{
1010
/** @test */
1111
function it_should_list_all_available_tasks()

tests/DeploymentTestCase.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace Lorisleiva\LaravelDeployer\Test;
4+
5+
class DeploymentTestCase extends TestCase
6+
{
7+
const REPOSITORY = __DIR__ . '/fixtures/repository';
8+
const RECIPES = __DIR__ . '/fixtures/recipes';
9+
const TMP = __DIR__ . '/fixtures/tmp';
10+
11+
protected $recipe = 'basic';
12+
13+
public function setUp()
14+
{
15+
parent::setUp();
16+
$this->resetTempDirectory();
17+
$this->resetRepository();
18+
}
19+
20+
public function tearDown()
21+
{
22+
parent::tearDown();
23+
$this->exec('rm -rf ' . static::TMP);
24+
$this->exec('rm -rf ' . static::REPOSITORY . '/.git');
25+
$this->exec('rm -f ' . static::REPOSITORY . '/deploy.php');
26+
}
27+
28+
public function resetTempDirectory()
29+
{
30+
$this->exec('rm -rf ' . static::TMP);
31+
mkdir(static::TMP);
32+
}
33+
34+
public function resetRepository()
35+
{
36+
$this->resetDeployFile();
37+
38+
$this->exec('rm -rf ' . static::REPOSITORY . '/.git');
39+
$this->runInRepository("git init");
40+
$this->runInRepository("git add .");
41+
$this->runInRepository("git config user.name 'John Smith'");
42+
$this->runInRepository("git config user.email 'john.smith@example.com'");
43+
$this->runInRepository("git commit -m 'init commit'");
44+
}
45+
46+
public function resetDeployFile()
47+
{
48+
$recipeFile = realpath(static::RECIPES . '/' . $this->recipe . '.php');
49+
$deployFile = static::REPOSITORY . '/deploy.php';
50+
51+
$this->exec("rm -f $deployFile");
52+
53+
if ($recipeFile) {
54+
$this->exec("cp $recipeFile $deployFile");
55+
}
56+
}
57+
}

tests/TestCase.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Lorisleiva\LaravelDeployer\Test;
44

55
use Illuminate\Support\Facades\Artisan;
6+
use Symfony\Component\Process\Process;
67

78
class TestCase extends \Orchestra\Testbench\TestCase
89
{
@@ -13,12 +14,29 @@ protected function getPackageProviders($app)
1314

1415
protected function getEnvironmentSetUp($app)
1516
{
16-
$app->setBasePath(__DIR__ . '/dummyApp');
17+
$app->setBasePath(__DIR__ . '/fixtures/repository');
1718
}
1819

1920
public function artisan($command, $parameters = [])
2021
{
21-
Artisan::call($command, $parameters);
22+
Artisan::call($command, $parameters + ['--no-ansi' => true]);
2223
return Artisan::output();
2324
}
25+
26+
public function runInRepository($command)
27+
{
28+
$this->exec("cd " . static::REPOSITORY . " && $command");
29+
}
30+
31+
public function runInRoot($command)
32+
{
33+
$this->exec("cd " . static::TMP . " && $command");
34+
}
35+
36+
public function exec($command)
37+
{
38+
$process = new Process($command);
39+
$process->mustRun();
40+
return trim($process->getOutput());
41+
}
2442
}

tests/DeployFileGeneratorTest.php renamed to tests/Unit/DeployFileGeneratorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22

3-
namespace Lorisleiva\LaravelDeployer\Test;
3+
namespace Lorisleiva\LaravelDeployer\Test\Unit;
44

55
use Lorisleiva\LaravelDeployer\DeployFileGenerator;
6+
use Lorisleiva\LaravelDeployer\Test\TestCase;
67

78
class DeployFileGeneratorTest extends TestCase
89
{

tests/ParseParametersTest.php renamed to tests/Unit/ParseParametersTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22

3-
namespace Lorisleiva\LaravelDeployer\Test;
3+
namespace Lorisleiva\LaravelDeployer\Test\Unit;
44

55
use Lorisleiva\LaravelDeployer\Commands\BaseCommand;
6+
use Lorisleiva\LaravelDeployer\Test\TestCase;
67
use Symfony\Component\Console\Input\StringInput;
78
use Symfony\Component\Console\Output\NullOutput;
89

tests/dummyApp/deploy.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/dummyApp/vendor/bin/dep

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/fixtures/recipes/basic.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Deployer;
4+
5+
require 'recipe/laravel-deployer.php';
6+
7+
set('repository', __DIR__ . '/../repository');
8+
set('branch', null);
9+
set('http_user', getenv('USER'));
10+
11+
localhost()
12+
->set('deploy_path', __DIR__ . '/../tmp');
13+
14+
// Mock composer install
15+
task('deploy:vendor', function() {
16+
$vendorFolder = realpath(__DIR__ . '../../../vendor');
17+
run("ln -s $vendorFolder {{release_path}}/vendor");
18+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
* text=auto
2+
*.css linguist-vendored
3+
*.scss linguist-vendored
4+
*.js linguist-vendored
5+
CHANGELOG.md export-ignore

tests/fixtures/repository/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/node_modules
2+
/public/hot
3+
/public/storage
4+
/storage/*.key
5+
.env
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace App\Console;
4+
5+
use Illuminate\Console\Scheduling\Schedule;
6+
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
7+
8+
class Kernel extends ConsoleKernel
9+
{
10+
/**
11+
* The Artisan commands provided by your application.
12+
*
13+
* @var array
14+
*/
15+
protected $commands = [
16+
//
17+
];
18+
19+
/**
20+
* Define the application's command schedule.
21+
*
22+
* @param \Illuminate\Console\Scheduling\Schedule $schedule
23+
* @return void
24+
*/
25+
protected function schedule(Schedule $schedule)
26+
{
27+
// $schedule->command('inspire')
28+
// ->hourly();
29+
}
30+
31+
/**
32+
* Register the commands for the application.
33+
*
34+
* @return void
35+
*/
36+
protected function commands()
37+
{
38+
$this->load(__DIR__.'/Commands');
39+
40+
require base_path('routes/console.php');
41+
}
42+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
7+
8+
class Handler extends ExceptionHandler
9+
{
10+
/**
11+
* A list of the exception types that are not reported.
12+
*
13+
* @var array
14+
*/
15+
protected $dontReport = [
16+
//
17+
];
18+
19+
/**
20+
* A list of the inputs that are never flashed for validation exceptions.
21+
*
22+
* @var array
23+
*/
24+
protected $dontFlash = [
25+
'password',
26+
'password_confirmation',
27+
];
28+
29+
/**
30+
* Report or log an exception.
31+
*
32+
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
33+
*
34+
* @param \Exception $exception
35+
* @return void
36+
*/
37+
public function report(Exception $exception)
38+
{
39+
parent::report($exception);
40+
}
41+
42+
/**
43+
* Render an exception into an HTTP response.
44+
*
45+
* @param \Illuminate\Http\Request $request
46+
* @param \Exception $exception
47+
* @return \Illuminate\Http\Response
48+
*/
49+
public function render($request, Exception $exception)
50+
{
51+
return parent::render($request, $exception);
52+
}
53+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Foundation\Bus\DispatchesJobs;
6+
use Illuminate\Routing\Controller as BaseController;
7+
use Illuminate\Foundation\Validation\ValidatesRequests;
8+
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
9+
10+
class Controller extends BaseController
11+
{
12+
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
13+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace App\Http;
4+
5+
use Illuminate\Foundation\Http\Kernel as HttpKernel;
6+
7+
class Kernel extends HttpKernel
8+
{
9+
/**
10+
* The application's global HTTP middleware stack.
11+
*
12+
* These middleware are run during every request to your application.
13+
*
14+
* @var array
15+
*/
16+
protected $middleware = [
17+
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
18+
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
19+
\App\Http\Middleware\TrimStrings::class,
20+
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
21+
\App\Http\Middleware\TrustProxies::class,
22+
];
23+
24+
/**
25+
* The application's route middleware groups.
26+
*
27+
* @var array
28+
*/
29+
protected $middlewareGroups = [
30+
'web' => [
31+
\App\Http\Middleware\EncryptCookies::class,
32+
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
33+
\Illuminate\Session\Middleware\StartSession::class,
34+
// \Illuminate\Session\Middleware\AuthenticateSession::class,
35+
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
36+
\App\Http\Middleware\VerifyCsrfToken::class,
37+
\Illuminate\Routing\Middleware\SubstituteBindings::class,
38+
],
39+
40+
'api' => [
41+
'throttle:60,1',
42+
'bindings',
43+
],
44+
];
45+
46+
/**
47+
* The application's route middleware.
48+
*
49+
* These middleware may be assigned to groups or used individually.
50+
*
51+
* @var array
52+
*/
53+
protected $routeMiddleware = [
54+
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
55+
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
56+
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
57+
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
58+
'can' => \Illuminate\Auth\Middleware\Authorize::class,
59+
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
60+
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
61+
];
62+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
6+
7+
class EncryptCookies extends Middleware
8+
{
9+
/**
10+
* The names of the cookies that should not be encrypted.
11+
*
12+
* @var array
13+
*/
14+
protected $except = [
15+
//
16+
];
17+
}

0 commit comments

Comments
 (0)