-
Notifications
You must be signed in to change notification settings - Fork 49
Tests Setup
JP Barbosa edited this page Mar 14, 2016
·
3 revisions
nano bootstrap/app.php
...
if (!empty($argv) && in_array('--env=testing', $argv)) {
$app->loadEnvironmentFrom('.env.testing');
}
return $app;
cp .env .env.testing
nano .env.testing
APP_ENV=testing
...
SQLITE_FILE=testing.sqlite
nano config/database.php
...
'sqlite' => [
'driver' => 'sqlite',
'database' => database_path(env('SQLITE_FILE', 'database.sqlite')),
'prefix' => '',
],
...
touch database/testing.sqlite
php artisan migrate --env=testing
composer require doctrine/dbal
php artisan make:console DbTruncate --command=db:truncate
nano app/Console/Commands/DbTruncate.php
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
class DbTruncate extends Command
{
...
protected $description = 'Truncate tables on testing environment.';
...
public function handle()
{
if (!\App::environment('testing')) {
echo 'Truncate aborted. You are not on a testing environment.';
return;
}
$tables = DB::connection()->getDoctrineSchemaManager()->listTableNames();
foreach ($tables as $name) {
//if you don't want to truncate migrations
if ($name == 'migrations') {
continue;
}
DB::table($name)->truncate();
}
}
}
nano app/Console/Kernel.php
class Kernel extends ConsoleKernel
{
...
protected $commands = [
...
\App\Console\Commands\DbTruncate::class,
];
...
}
composer require codeception/codeception --dev
vendor/bin/codecept bootstrap
nano tests/unit.suite.yml
class_name: UnitTester
modules:
enabled:
- Laravel5
- Asserts
- \Helper\Unit
nano tests/functional.suite.yml
class_name: FunctionalTester
modules:
enabled:
- Laravel5:
cleanup: false
environment_file: .env.testing
- REST:
depends: PhpBrowser
url: 'http://localhost:8000'
- \Helper\Functional
vendor/bin/codecept run
Codeception PHP Testing Framework v2.1.1
Powered by PHPUnit 4.7.7 by Sebastian Bergmann and contributors.
Acceptance Tests (0) ------------------------
---------------------------------------------
Functional Tests (0) ------------------------
---------------------------------------------
Unit Tests (0) ------------------------------
---------------------------------------------
Time: 174 ms, Memory: 13.50Mb
No tests executed!
git add .
git commit -m "Add tests setup"
Next step: Functional Tests
- Setup
- Basic CRUD
- Validation
- Views
- Association
- Association Controller
- Association Views
- Basic Template
- Bootstrap
- Bootstrap CRUD
- Alerts
- Welcome Page
- Ajax CRUD
- Send Email
- Send Email Views
- Jobs Queue
- Captcha
- Async External Content
- Cached External Content
- Tests Setup
- Functional Tests
- Acceptance Tests
- Continuous Integration
- Deploy with Heroku
- Deploy with Forge
- Update README