tests and laravel models

This commit is contained in:
2017-10-06 22:32:31 -04:00
parent 1d3e8e3117
commit 81e40d304e
27 changed files with 495 additions and 463 deletions

View File

@@ -1,4 +1,5 @@
<?php
// This is global bootstrap for autoloading
include_once 'vendor/autoload.php';
include_once 'vendor/autoload.php';
\Codeception\Util\Autoload::addNamespace('Tests', codecept_root_dir().'tests/unit');

View File

@@ -14,6 +14,7 @@ S:http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html
Z:Andy Hornby
X:3
T:Short and Sweet
M:4/4
K:C
gaab babc :|

View File

@@ -1,5 +1,5 @@
<?php
namespace arr;
namespace Tests\Laravel5;
use \UnitTester;
use XaiCorp\AbcParser\Models\Laravel5\Abc;
@@ -142,6 +142,7 @@ e2g efg|c2e cde|dcB AGF|E3E2
1 => [
'X' => '3',
'T' => ['Short and Sweet'],
'M' => '4/4',
'K' => 'C',
'music' => 'gaab babc :|'

View File

@@ -0,0 +1,63 @@
<?php
namespace Tests\Laravel5;
use Codeception\TestCase\Test;
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
use XaiCorp\AbcParser\Models\Laravel5\Abc;
use XaiCorp\AbcParser\Models\Laravel5\Collection;
use XaiCorp\AbcParser\Models\Laravel5\CollectionAttribute;
use XaiCorp\AbcParser\Parser;
class AbcParserDBTest extends BaseDbTest
{
/**
* @var string
*/
protected $dataDir;
/**
* @var \XaiCorp\AbcParser\Interfaces\Builder60
*/
protected $builder;
/**
* @var \UnitTester
*/
protected $tester;
public function __construct()
{
$this->dataDir = codecept_data_dir();
}
// tests: trying to...
public function testSaveAbcFromExample1()
{
$abc = file_get_contents($this->dataDir.'/abc/valid_abc_1.abc');
$parser = new Parser($this->builder);
$result = $parser->parseABC($abc);
$this->assertTrue($result->save());
}
public function testSaveAbcFromExample2()
{
$abc = file_get_contents($this->dataDir.'/abc/valid_abc_2.abc');
$parser = new Parser($this->builder);
$result = $parser->parseABC($abc);
$this->assertTrue($result->save());
}
public function testSaveAbcFromExample3()
{
$abc = file_get_contents($this->dataDir.'/abc/valid_abc_3.abc');
$parser = new Parser($this->builder);
$result = $parser->parseABC($abc);
$this->assertTrue($result->save());
$this->seeInDatabase('tune_settings', []);
$this->seeInDatabase('tunes', []);
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace Tests\Laravel5;
use Codeception\TestCase\Test;
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
use XaiCorp\AbcParser\Models\Laravel5\Abc;
class BaseDbTest extends Test
{
use TestHelperTrait;
/**
* @var \UnitTester
*/
protected $tester;
/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function getEnvironmentSetUp($app)
{
// Setup default database to use sqlite :memory:
$app['config']->set('database.default', 'testbench');
$app['config']->set('database.connections.testbench', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
$app->setBasePath(dirname(dirname(dirname(__DIR__))));
$Artisan = $app->make('Artisan');
$Artisan::call('migrate');
}
protected function _before()
{
$this->startApplication();
$db = app()->make('db');
$db->beginTransaction();
$this->withFactories(__DIR__ . '/factories');
$this->builder = new Abc();
}
protected function _after()
{
$db = app()->make('db');
$db->rollBack();
$this->stopApplication();
}
}

View File

@@ -1,61 +1,22 @@
<?php
namespace Laravel5;
namespace Tests\Laravel5;
use Codeception\TestCase\Test;
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
use Webpatser\Uuid\Uuid;
use XaiCorp\AbcParser\Models\Laravel5\Collection;
use XaiCorp\AbcParser\Models\Laravel5\CollectionAttribute;
use XaiCorp\AbcParser\Models\Laravel5\Person;
use XaiCorp\AbcParser\Models\Laravel5\Tune;
use XaiCorp\AbcParser\Models\Laravel5\TuneAttribute;
class CollectionAttributeTest extends Test
class CollectionAttributeTest extends BaseDbTest
{
use TestHelperTrait;
/**
* @var \UnitTester
*/
protected $tester;
/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function getEnvironmentSetUp($app)
{
// Setup default database to use sqlite :memory:
$app['config']->set('database.default', 'testbench');
$app['config']->set('database.connections.testbench', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
$app->setBasePath(dirname(dirname(dirname(__DIR__))));
$Artisan = $app->make('Artisan');
$Artisan::call('migrate');
}
protected function _before()
{
$this->startApplication();
$db = app()->make('db');
$db->beginTransaction();
$this->withFactories(__DIR__.'/factories');
}
protected function _after()
{
$db = app()->make('db');
$db->rollBack();
$this->stopApplication();
}
// tests: trying to...
public function testMakeModel()
@@ -128,7 +89,7 @@ class CollectionAttributeTest extends Test
public function testTuneIdValidation()
{
$model = factory(CollectionAttribute::class)->make([]);
$model->collection_id += 1;
$model->collection_id = Uuid::generate(4);
$this->assertFalse($model->validate());
}

View File

@@ -1,19 +1,20 @@
<?php
namespace Laravel5;
namespace Tests\Laravel5;
use Codeception\TestCase\Test;
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
use Faker\Test\Provider\BaseTest;
use XaiCorp\AbcParser\Models\Laravel5\Collection;
use XaiCorp\AbcParser\Models\Laravel5\CollectionAttribute;
class CollectionTest extends Test
class CollectionTest extends BaseDbTest
{
use TestHelperTrait;
// use TestHelperTrait;
/**
* @var \UnitTester
*/
protected $tester;
// /**
// * @var \UnitTester
// */
// protected $tester;
/**
* Define environment setup.
@@ -21,36 +22,36 @@ class CollectionTest extends Test
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function getEnvironmentSetUp($app)
{
// Setup default database to use sqlite :memory:
$app['config']->set('database.default', 'testbench');
$app['config']->set('database.connections.testbench', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
$app->setBasePath(dirname(dirname(dirname(__DIR__))));
$Artisan = $app->make('Artisan');
$Artisan::call('migrate');
}
protected function _before()
{
$this->startApplication();
$db = app()->make('db');
$db->beginTransaction();
$this->withFactories(__DIR__.'/factories');
}
protected function _after()
{
$db = app()->make('db');
$db->rollBack();
$this->stopApplication();
}
// protected function getEnvironmentSetUp($app)
// {
// // Setup default database to use sqlite :memory:
// $app['config']->set('database.default', 'testbench');
// $app['config']->set('database.connections.testbench', [
// 'driver' => 'sqlite',
// 'database' => ':memory:',
// 'prefix' => '',
// ]);
// $app->setBasePath(dirname(dirname(dirname(__DIR__))));
// $Artisan = $app->make('Artisan');
// $Artisan::call('migrate');
// }
//
//
// protected function _before()
// {
// $this->startApplication();
// $db = app()->make('db');
// $db->beginTransaction();
//
// $this->withFactories(__DIR__.'/factories');
// }
//
// protected function _after()
// {
// $db = app()->make('db');
// $db->rollBack();
// $this->stopApplication();
// }
// tests: trying to...

View File

@@ -1,60 +1,17 @@
<?php
namespace Laravel5;
namespace Tests\Laravel5;
use Codeception\TestCase\Test;
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
use XaiCorp\AbcParser\Models\Laravel5\Person;
class PersonTest extends Test
class PersonTest extends BaseDbTest
{
use TestHelperTrait;
/**
* @var \UnitTester
*/
protected $tester;
/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function getEnvironmentSetUp($app)
{
// Setup default database to use sqlite :memory:
$app['config']->set('database.default', 'testbench');
$app['config']->set('database.connections.testbench', [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'abc-api-testing',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'username' => 'abc-api',
'password' => 'sio2nf0d'
]);
}
protected function _before()
{
$this->startApplication();
$db = app()->make('db');
$db->beginTransaction();
$this->withFactories(__DIR__.'/factories');
}
protected function _after()
{
$db = app()->make('db');
$db->rollBack();
$this->stopApplication();
}
// tests: trying to...
public function testMakeModel()
@@ -70,7 +27,10 @@ class PersonTest extends Test
public function testNameIsMassAssignable()
{
$name = "test1";
$model = Person::create(['name'=>$name]);
$model = Person::create([
'name' =>$name,
'email' => 'me@example.com',
]);
$this->assertInstanceOf(Person::class, $model);
$this->assertEquals($name, $model->name);

View File

@@ -1,62 +1,20 @@
<?php
namespace Laravel5;
namespace Tests\Laravel5;
use Codeception\TestCase\Test;
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
use Webpatser\Uuid\Uuid;
use XaiCorp\AbcParser\Models\Laravel5\Person;
use XaiCorp\AbcParser\Models\Laravel5\Tune;
use XaiCorp\AbcParser\Models\Laravel5\TuneAttribute;
class TuneAttributeTest extends Test
class TuneAttributeTest extends BaseDbTest
{
use TestHelperTrait;
/**
* @var \UnitTester
*/
protected $tester;
/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function getEnvironmentSetUp($app)
{
// Setup default database to use sqlite :memory:
$app['config']->set('database.default', 'testbench');
$app['config']->set('database.connections.testbench', [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'abc-api-testing',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'username' => 'abc-api',
'password' => 'sio2nf0d'
]);
}
protected function _before()
{
$this->startApplication();
$db = app()->make('db');
$db->beginTransaction();
$this->withFactories(__DIR__.'/factories');
}
protected function _after()
{
$db = app()->make('db');
$db->rollBack();
$this->stopApplication();
}
// tests: trying to...
public function testMakeModel()
@@ -129,7 +87,7 @@ class TuneAttributeTest extends Test
public function testTuneIdValidation()
{
$model = factory(TuneAttribute::class)->make([]);
$model->tune_id += 1;
$model->tune_id = Uuid::generate(4);
$this->assertFalse($model->validate());
}

View File

@@ -1,62 +1,20 @@
<?php
namespace Laravel5;
namespace Tests\Laravel5;
use Codeception\TestCase\Test;
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
use Webpatser\Uuid\Uuid;
use XaiCorp\AbcParser\Models\Laravel5\Person;
use XaiCorp\AbcParser\Models\Laravel5\TuneSetting;
use XaiCorp\AbcParser\Models\Laravel5\TuneSettingAttribute;
class TuneSettingAttributeTest extends Test
class TuneSettingAttributeTest extends BaseDbTest
{
use TestHelperTrait;
/**
* @var \UnitTester
*/
protected $tester;
/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function getEnvironmentSetUp($app)
{
// Setup default database to use sqlite :memory:
$app['config']->set('database.default', 'testbench');
$app['config']->set('database.connections.testbench', [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'abc-api-testing',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'username' => 'abc-api',
'password' => 'sio2nf0d'
]);
}
protected function _before()
{
$this->startApplication();
$db = app()->make('db');
$db->beginTransaction();
$this->withFactories(__DIR__.'/factories');
}
protected function _after()
{
$db = app()->make('db');
$db->rollBack();
$this->stopApplication();
}
// tests: trying to...
public function testMakeModel()
@@ -129,7 +87,7 @@ class TuneSettingAttributeTest extends Test
public function testTuneSettingIdValidation()
{
$model = factory(TuneSettingAttribute::class)->make([]);
$model->setting_id += 1;
$model->setting_id = Uuid::generate(4);
$this->assertFalse($model->validate());
}

View File

@@ -1,5 +1,5 @@
<?php
namespace Laravel5;
namespace Tests\Laravel5;
use Codeception\TestCase\Test;
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
@@ -9,63 +9,13 @@ use XaiCorp\AbcParser\Models\Laravel5\TuneAttribute;
use XaiCorp\AbcParser\Models\Laravel5\TuneSetting;
use XaiCorp\AbcParser\Models\Laravel5\TuneSettingAttribute;
class TuneSettingTest extends Test
class TuneSettingTest extends BaseDbTest
{
use TestHelperTrait;
/**
* @var \UnitTester
*/
protected $tester;
/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function getEnvironmentSetUp($app)
{
// Setup default database to use sqlite :memory:
$app['config']->set('database.default', 'testbench');
// $app['config']->set('database.connections.testbench', [
// 'driver' => 'mysql',
// 'host' => 'localhost',
// 'database' => 'abc-api-testing',
// 'charset' => 'utf8',
// 'collation' => 'utf8_unicode_ci',
// 'prefix' => '',
// 'strict' => true,
// 'username' => 'abc-api',
// 'password' => 'sio2nf0d'
// ]);
$app['config']->set('database.connections.testbench', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
$app->setBasePath(dirname(dirname(dirname(__DIR__))));
$Artisan = $app->make('Artisan');
$Artisan::call('migrate');
}
protected function _before()
{
$this->startApplication();
$db = app()->make('db');
$db->beginTransaction();
$this->withFactories(__DIR__.'/factories');
}
protected function _after()
{
$db = app()->make('db');
$db->rollBack();
$this->stopApplication();
}
// tests: trying to...
public function testMakeModel()

View File

@@ -1,5 +1,5 @@
<?php
namespace Laravel5;
namespace Tests\Laravel5;
use Codeception\TestCase\Test;
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
@@ -7,62 +7,13 @@ use XaiCorp\AbcParser\Models\Laravel5\Person;
use XaiCorp\AbcParser\Models\Laravel5\Tune;
use XaiCorp\AbcParser\Models\Laravel5\TuneAttribute;
class TuneTest extends Test
class TuneTest extends BaseDbTest
{
use TestHelperTrait;
/**
* @var \UnitTester
*/
protected $tester;
/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function getEnvironmentSetUp($app)
{
// Setup default database to use sqlite :memory:
$app['config']->set('database.default', 'testbench');
// $app['config']->set('database.connections.testbench', [
// 'driver' => 'mysql',
// 'host' => 'localhost',
// 'database' => 'abc-api-testing',
// 'charset' => 'utf8',
// 'collation' => 'utf8_unicode_ci',
// 'prefix' => '',
// 'strict' => true,
// 'username' => 'abc-api',
// 'password' => 'sio2nf0d'
// ]);
$app['config']->set('database.connections.testbench', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
$app->setBasePath(dirname(dirname(dirname(__DIR__))));
$Artisan = $app->make('Artisan');
$Artisan::call('migrate');
}
protected function _before()
{
$this->startApplication();
$db = app()->make('db');
$db->beginTransaction();
$this->withFactories(__DIR__.'/factories');
}
protected function _after()
{
$db = app()->make('db');
$db->rollBack();
$this->stopApplication();
}
// tests: trying to...