initial commit

This commit is contained in:
2016-04-15 21:38:56 -04:00
commit 1d3e8e3117
79 changed files with 16223 additions and 0 deletions

View File

@@ -0,0 +1,156 @@
<?php
namespace arr;
use \UnitTester;
use XaiCorp\AbcParser\Models\Laravel5\Abc;
use XaiCorp\AbcParser\Parser;
class AbcParserCest
{
/**
* @var string
*/
protected $dataDir;
/**
* @var \XaiCorp\AbcParser\Interfaces\Builder
*/
protected $builder;
/**
* @var Parser;
*/
protected $parser;
public function __construct()
{
$this->dataDir = codecept_data_dir();
}
public function _before(UnitTester $I)
{
$this->builder = new Abc();
}
public function _after(UnitTester $I)
{
unset($builder);
}
// tests: trying to...
public function createParser(UnitTester $I)
{
$parser = new Parser($this->builder);
$I->assertInstanceOf(Parser::class, $parser);
}
public function seeParseEmptyAbcWithoutErrors(UnitTester $I)
{
$abc = '';
$parser = new Parser($this->builder);
$result = $parser->parseABC($abc);
$I->assertEmpty($result);
}
public function seeParseABCExample1(UnitTester $I)
{
$abc = file_get_contents($this->dataDir.'/abc/valid_abc_1.abc');
$parser = new Parser($this->builder);
$expected = [
1 => [
'X' => '3',
'M' => '4/4',
'K' => 'C',
'music' => 'gaab babc :|'
],
];
$result = $parser->parseABC($abc);
$I->assertNotEmpty($result);
$resultArray = $result->toArray();
$I->assertEquals($expected, $resultArray);
}
public function seeParseABCExample2(UnitTester $I)
{
$abc = file_get_contents($this->dataDir.'/abc/valid_abc_2.abc');
$parser = new Parser($this->builder);
$expected = [
1 => [
'X' => '40',
'T' => ['Abbotts Bromley Horn Dance'],
'A' => ['trad'],
'C' => ['trad.'],
'D' => ['None'],
'G' => ['lute'],
'H' => [
'Thousand year old tradition',
'The Horns live in the church and are removed for the dance once a year'
],
'R' => ['Jig'],
'F' => ['none.abc'],
'B' => ['Traditional English tunes'],
'W' => ['None'],
'Q' => '1/8=80',
'L' => '1/8',
'M' => '6/8',
'N' => ['Traditional English'],
'O' => ['England'],
'Z' => ['Andy Hornby'],
'S' => ['http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html'],
'P' => 'ABC',
'K' => 'G',
'music' => 'e|B2e G2e|B2e E2G|FGA GAB|1AGF G2:|2AGF E2|
|e|c2e cde|A2c ABc|FGA GFE|_E=EF B,2g|
e2g efg|c2e cde|dcB AGF|E3E2
|:A|BcB e3|BcB f3|BcB AGF|1G2F G2:|2E3-E2|]'
],
];
$result = $parser->parseABC($abc);
$I->assertNotEmpty($result);
$resultArray = $result->toArray();
$I->assertEquals($expected, $resultArray);
}
public function seeParseABCExample3(UnitTester $I)
{
$abc = file_get_contents($this->dataDir.'/abc/valid_abc_3.abc');
$parser = new Parser($this->builder);
$expected = [
'A' => ['trad'],
'C' => ['trad.'],
'D' => ['None'],
'H' => [
'Thousand year old tradition',
'The Horns live in the church and are removed for the dance once a year'
],
'R' => ['Jig'],
'F' => ['none.abc'],
'B' => ['Traditional English tunes'],
'L' => '1/8',
'M' => '6/8',
'N' => ['Traditional English'],
'O' => ['England'],
'S' => ['http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html'],
'Z' => ['Andy Hornby'],
1 => [
'X' => '3',
'M' => '4/4',
'K' => 'C',
'music' => 'gaab babc :|'
]
];
$result = $parser->parseABC($abc);
$I->assertNotEmpty($result->toArray());
$I->assertEquals($expected, $result->toArray());
}
}

View File

@@ -0,0 +1,155 @@
<?php
namespace Laravel5;
use Codeception\TestCase\Test;
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
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
{
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()
{
$collection = factory(Collection::class)->create();
$type = 'Note';
$value = 'a title';
$ordering = 1;
$model = new CollectionAttribute();
$model->collection_id = $collection->id;
$model->type = $type;
$model->string = $value;
$model->ordering = $ordering;
$this->assertInstanceOf(CollectionAttribute::class, $model);
$this->assertEquals($collection->id, $model->collection_id);
$this->assertEquals($type, $model->type);
$this->assertEquals($value, $model->string);
$this->assertEquals($ordering, $model->ordering);
}
public function testMassAssignable()
{
$collection = factory(Collection::class)->create();
$type = 'Note';
$value = 'a title';
$ordering = 1;
$model = CollectionAttribute::create([
'collection_id' => $collection->id,
'type' => $type,
'string' => $value,
'ordering' => $ordering
]);
$this->assertInstanceOf(CollectionAttribute::class, $model);
$this->assertEquals($collection->id, $model->collection_id);
$this->assertEquals($type, $model->type);
$this->assertEquals($value, $model->string);
$this->assertEquals($ordering, $model->ordering);
}
public function testFactory()
{
$model = factory(CollectionAttribute::class)->make([]);
$this->assertInstanceOf(CollectionAttribute::class, $model);
$this->assertNotNull($model->collection_id);
$this->assertNotNull($model->type);
$this->assertNotNull($model->string);
$this->assertNotNull($model->ordering);
$this->assertTrue($model->save(), json_encode($model->getMessages()));
}
public function testValidationAppliedOnSave()
{
$model = factory(CollectionAttribute::class)->make([]);
$model->type = 'NotType';
$this->assertFalse($model->save());
}
public function testTypeValidation()
{
$model = factory(CollectionAttribute::class)->make([]);
$model->type = 'NotType';
$this->assertFalse($model->validate());
}
public function testTuneIdValidation()
{
$model = factory(CollectionAttribute::class)->make([]);
$model->collection_id += 1;
$this->assertFalse($model->validate());
}
public function testStringValidation()
{
$longString = '';
for ($i=0; $i < 300; $i++) {
$longString .= 's';
}
$model = factory(CollectionAttribute::class)->make([]);
$model->string = $longString;
$this->assertFalse($model->validate());
}
public function testOrderingValidation()
{
$model = factory(CollectionAttribute::class)->make([]);
$model->ordering = "fourth";
$this->assertFalse($model->validate());
}
}

View File

@@ -0,0 +1,522 @@
<?php
namespace Laravel5;
use Codeception\TestCase\Test;
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
use XaiCorp\AbcParser\Models\Laravel5\Collection;
use XaiCorp\AbcParser\Models\Laravel5\CollectionAttribute;
class CollectionTest 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');
}
protected function _after()
{
$db = app()->make('db');
$db->rollBack();
$this->stopApplication();
}
// tests: trying to...
public function testMakeModel()
{
$name = "test1";
$model = new Collection();
$model->name = $name;
$this->assertInstanceOf(Collection::class, $model);
$this->assertEquals($name, $model->name);
}
public function testNameIsMassAssignable()
{
$name = "test1";
$model = Collection::create(['name'=>$name]);
$this->assertInstanceOf(Collection::class, $model);
$this->assertEquals($name, $model->name);
}
public function testFactorySetsName()
{
$model = factory(Collection::class)->make([]);
$this->assertInstanceOf(Collection::class, $model);
$this->assertNotEmpty($model->name);
}
public function testAppendToCollection()
{
$setting = new \stdClass();
$model = factory(Collection::class)->make([]);
$result = $model->appendSetting($setting);
$this->assertInstanceOf(\Illuminate\Support\Collection::class, $result);
$this->assertContains($setting, $result);
}
public function testCanGetAuthorAttribute()
{
$string = 'Arthur';
$model = factory(Collection::class)->create([]);
$attr = factory(CollectionAttribute::class)->create([
'collection_id' => $model->id,
'type' => 'Author',
'string' => $string,
]);
$model = $model->fresh();
$this->assertInstanceOf(Collection::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($string, $model->A[0]);
}
public function testSetAuthorAttribute()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->A = $values;
$this->assertEquals($values[0], $model->A[0]);
$this->assertEquals($values[1], $model->A[1]);
}
public function testAuthorAttributeSaves()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->A = $values;
$model->save();
$model = $model->fresh();
$this->assertEquals($values[0], $model->A[0]);
$this->assertEquals($values[1], $model->A[1]);
}
public function testCanGetComposerAttribute()
{
$string = 'Arthur';
$model = factory(Collection::class)->create([]);
$attr = factory(CollectionAttribute::class)->create([
'collection_id' => $model->id,
'type' => 'Composer',
'string' => $string,
]);
$model = $model->fresh();
$this->assertInstanceOf(Collection::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($string, $model->C[0]);
}
public function testSetComposerAttribute()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->C = $values;
$this->assertEquals($values[0], $model->C[0]);
$this->assertEquals($values[1], $model->C[1]);
}
public function testComposerAttributeSaves()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->C = $values;
$model->save();
$model = $model->fresh();
$this->assertEquals($values[0], $model->C[0]);
$this->assertEquals($values[1], $model->C[1]);
}
public function testCanGetDiscographyAttribute()
{
$string = 'Arthur';
$model = factory(Collection::class)->create([]);
$attr = factory(CollectionAttribute::class)->create([
'collection_id' => $model->id,
'type' => 'Discography',
'string' => $string,
]);
$model = $model->fresh();
$this->assertInstanceOf(Collection::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($string, $model->D[0]);
}
public function testSetDiscographyAttribute()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->D = $values;
$this->assertEquals($values[0], $model->D[0]);
$this->assertEquals($values[1], $model->D[1]);
}
public function testDiscographyAttributeSaves()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->D = $values;
$model->save();
$model = $model->fresh();
$this->assertEquals($values[0], $model->D[0]);
$this->assertEquals($values[1], $model->D[1]);
}
public function testCanGetRhythmAttribute()
{
$string = 'Arthur';
$model = factory(Collection::class)->create([]);
$attr = factory(CollectionAttribute::class)->create([
'collection_id' => $model->id,
'type' => 'Rhythm',
'string' => $string,
]);
$model = $model->fresh();
$this->assertInstanceOf(Collection::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($string, $model->R[0]);
}
public function testSetRhythmAttribute()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->R = $values;
$this->assertEquals($values[0], $model->R[0]);
$this->assertEquals($values[1], $model->R[1]);
}
public function testRhythmAttributeSaves()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->R = $values;
$model->save();
$model = $model->fresh();
$this->assertEquals($values[0], $model->R[0]);
$this->assertEquals($values[1], $model->R[1]);
}
public function testCanGetHistoryAttribute()
{
$string = 'Arthur';
$model = factory(Collection::class)->create([]);
$attr = factory(CollectionAttribute::class)->create([
'collection_id' => $model->id,
'type' => 'History',
'string' => $string,
]);
$model = $model->fresh();
$this->assertInstanceOf(Collection::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($string, $model->H[0]);
}
public function testSetHistoryAttribute()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->H = $values;
$this->assertEquals($values[0], $model->H[0]);
$this->assertEquals($values[1], $model->H[1]);
}
public function testHistoryAttributeSaves()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->A = $values;
$model->save();
$model = $model->fresh();
$this->assertEquals($values[0], $model->A[0]);
$this->assertEquals($values[1], $model->A[1]);
}
public function testCanGetFileAttribute()
{
$string = 'Arthur';
$model = factory(Collection::class)->create([]);
$attr = factory(CollectionAttribute::class)->create([
'collection_id' => $model->id,
'type' => 'File',
'string' => $string,
]);
$model = $model->fresh();
$this->assertInstanceOf(Collection::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($string, $model->F[0]);
}
public function testSetFileAttribute()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->F = $values;
$this->assertEquals($values[0], $model->F[0]);
$this->assertEquals($values[1], $model->F[1]);
}
public function testFileAttributeSaves()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->F = $values;
$model->save();
$model = $model->fresh();
$this->assertEquals($values[0], $model->F[0]);
$this->assertEquals($values[1], $model->F[1]);
}
public function testCanGetBookAttribute()
{
$string = 'Arthur';
$model = factory(Collection::class)->create([]);
$attr = factory(CollectionAttribute::class)->create([
'collection_id' => $model->id,
'type' => 'Book',
'string' => $string,
]);
$model = $model->fresh();
$this->assertInstanceOf(Collection::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($string, $model->B[0]);
}
public function testSetBookAttribute()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->B = $values;
$this->assertEquals($values[0], $model->B[0]);
$this->assertEquals($values[1], $model->B[1]);
}
public function testBookAttributeSaves()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->B = $values;
$model->save();
$model = $model->fresh();
$this->assertEquals($values[0], $model->B[0]);
$this->assertEquals($values[1], $model->B[1]);
}
public function testCanGetNoteAttribute()
{
$string = 'Arthur';
$model = factory(Collection::class)->create([]);
$attr = factory(CollectionAttribute::class)->create([
'collection_id' => $model->id,
'type' => 'Note',
'string' => $string,
]);
$model = $model->fresh();
$this->assertInstanceOf(Collection::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($string, $model->N[0]);
}
public function testSetNoteAttribute()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->N = $values;
$this->assertEquals($values[0], $model->N[0]);
$this->assertEquals($values[1], $model->N[1]);
}
public function testNoteAttributeSaves()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->N = $values;
$model->save();
$model = $model->fresh();
$this->assertEquals($values[0], $model->N[0]);
$this->assertEquals($values[1], $model->N[1]);
}
public function testCanGetSourceAttribute()
{
$string = 'Arthur';
$model = factory(Collection::class)->create([]);
$attr = factory(CollectionAttribute::class)->create([
'collection_id' => $model->id,
'type' => 'Source',
'string' => $string,
]);
$model = $model->fresh();
$this->assertInstanceOf(Collection::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($string, $model->S[0]);
}
public function testSetSourceAttribute()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->S = $values;
$this->assertEquals($values[0], $model->S[0]);
$this->assertEquals($values[1], $model->S[1]);
}
public function testSourceAttributeSaves()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->S = $values;
$model->save();
$model = $model->fresh();
$this->assertEquals($values[0], $model->S[0]);
$this->assertEquals($values[1], $model->S[1]);
}
public function testCanGetTranscriberAttribute()
{
$string = 'Arthur';
$model = factory(Collection::class)->create([]);
$attr = factory(CollectionAttribute::class)->create([
'collection_id' => $model->id,
'type' => 'Transcriber',
'string' => $string,
]);
$model = $model->fresh();
$this->assertInstanceOf(Collection::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($string, $model->Z[0]);
}
public function testSetTranscriberAttribute()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->Z = $values;
$this->assertEquals($values[0], $model->Z[0]);
$this->assertEquals($values[1], $model->Z[1]);
}
public function testTranscriberAttributeSaves()
{
$values = ['England', 'Scotland'];
$model = factory(Collection::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->Z = $values;
$model->save();
$model = $model->fresh();
$this->assertEquals($values[0], $model->Z[0]);
$this->assertEquals($values[1], $model->Z[1]);
}
}

View File

@@ -0,0 +1,86 @@
<?php
namespace Laravel5;
use Codeception\TestCase\Test;
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
use XaiCorp\AbcParser\Models\Laravel5\Person;
class PersonTest 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' => '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()
{
$name = "test1";
$model = new Person();
$model->name = $name;
$this->assertInstanceOf(Person::class, $model);
$this->assertEquals($name, $model->name);
}
public function testNameIsMassAssignable()
{
$name = "test1";
$model = Person::create(['name'=>$name]);
$this->assertInstanceOf(Person::class, $model);
$this->assertEquals($name, $model->name);
}
public function testFactorySetsName()
{
$model = factory(Person::class)->make([]);
$this->assertInstanceOf(Person::class, $model);
$this->assertNotEmpty($model->name);
}
}

View File

@@ -0,0 +1,156 @@
<?php
namespace Laravel5;
use Codeception\TestCase\Test;
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
use XaiCorp\AbcParser\Models\Laravel5\Person;
use XaiCorp\AbcParser\Models\Laravel5\Tune;
use XaiCorp\AbcParser\Models\Laravel5\TuneAttribute;
class TuneAttributeTest 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' => '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()
{
$tune = factory(Tune::class)->create();
$type = 'Title';
$title = 'a title';
$ordering = 1;
$model = new TuneAttribute();
$model->tune_id = $tune->id;
$model->type = $type;
$model->string = $title;
$model->ordering = $ordering;
$this->assertInstanceOf(TuneAttribute::class, $model);
$this->assertEquals($tune->id, $model->tune_id);
$this->assertEquals($type, $model->type);
$this->assertEquals($title, $model->string);
$this->assertEquals($ordering, $model->ordering);
}
public function testMassAssignable()
{
$tune = factory(Tune::class)->create();
$type = 'Title';
$title = 'a title';
$ordering = 1;
$model = TuneAttribute::create([
'tune_id' => $tune->id,
'type' => $type,
'string' => $title,
'ordering' => $ordering
]);
$this->assertInstanceOf(TuneAttribute::class, $model);
$this->assertEquals($tune->id, $model->tune_id);
$this->assertEquals($type, $model->type);
$this->assertEquals($title, $model->string);
$this->assertEquals($ordering, $model->ordering);
}
public function testFactory()
{
$model = factory(TuneAttribute::class)->make([]);
$this->assertInstanceOf(TuneAttribute::class, $model);
$this->assertNotNull($model->tune_id);
$this->assertNotNull($model->type);
$this->assertNotNull($model->string);
$this->assertNotNull($model->ordering);
$this->assertTrue($model->save(), json_encode($model->getMessages()));
}
public function testValidationAppliedOnSave()
{
$model = factory(TuneAttribute::class)->make([]);
$model->type = 'NotType';
$this->assertFalse($model->save());
}
public function testTypeValidation()
{
$model = factory(TuneAttribute::class)->make([]);
$model->type = 'NotType';
$this->assertFalse($model->validate());
}
public function testTuneIdValidation()
{
$model = factory(TuneAttribute::class)->make([]);
$model->tune_id += 1;
$this->assertFalse($model->validate());
}
public function testStringValidation()
{
$longString = '';
for ($i=0; $i < 300; $i++) {
$longString .= 's';
}
$model = factory(TuneAttribute::class)->make([]);
$model->string = $longString;
$this->assertFalse($model->validate());
}
public function testOrderingValidation()
{
$model = factory(TuneAttribute::class)->make([]);
$model->ordering = "fourth";
$this->assertFalse($model->validate());
}
}

View File

@@ -0,0 +1,156 @@
<?php
namespace Laravel5;
use Codeception\TestCase\Test;
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
use XaiCorp\AbcParser\Models\Laravel5\Person;
use XaiCorp\AbcParser\Models\Laravel5\TuneSetting;
use XaiCorp\AbcParser\Models\Laravel5\TuneSettingAttribute;
class TuneSettingAttributeTest 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' => '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()
{
$tune = factory(TuneSetting::class)->create();
$type = 'Title';
$title = 'a title';
$ordering = 1;
$model = new TuneSettingAttribute();
$model->tune_id = $tune->id;
$model->type = $type;
$model->string = $title;
$model->ordering = $ordering;
$this->assertInstanceOf(TuneSettingAttribute::class, $model);
$this->assertEquals($tune->id, $model->tune_id);
$this->assertEquals($type, $model->type);
$this->assertEquals($title, $model->string);
$this->assertEquals($ordering, $model->ordering);
}
public function testMassAssignable()
{
$setting = factory(TuneSetting::class)->create();
$type = 'Notes';
$value = 'a little note';
$ordering = 1;
$model = TuneSettingAttribute::create([
'setting_id' => $setting->id,
'type' => $type,
'string' => $value,
'ordering' => $ordering
]);
$this->assertInstanceOf(TuneSettingAttribute::class, $model);
$this->assertEquals($setting->id, $model->setting_id);
$this->assertEquals($type, $model->type);
$this->assertEquals($value, $model->string);
$this->assertEquals($ordering, $model->ordering);
}
public function testFactory()
{
$model = factory(TuneSettingAttribute::class)->make([]);
$this->assertInstanceOf(TuneSettingAttribute::class, $model);
$this->assertNotNull($model->setting_id);
$this->assertNotNull($model->type);
$this->assertNotNull($model->string);
$this->assertNotNull($model->ordering);
$this->assertTrue($model->save(), json_encode($model->getMessages()));
}
public function testValidationAppliedOnSave()
{
$model = factory(TuneSettingAttribute::class)->make([]);
$model->type = 'NotType';
$this->assertFalse($model->save());
}
public function testTypeValidation()
{
$model = factory(TuneSettingAttribute::class)->make([]);
$model->type = 'NotType';
$this->assertFalse($model->validate());
}
public function testTuneSettingIdValidation()
{
$model = factory(TuneSettingAttribute::class)->make([]);
$model->setting_id += 1;
$this->assertFalse($model->validate());
}
public function testStringValidation()
{
$longString = '';
for ($i=0; $i < 300; $i++) {
$longString .= 's';
}
$model = factory(TuneSettingAttribute::class)->make([]);
$model->string = $longString;
$this->assertFalse($model->validate());
}
public function testOrderingValidation()
{
$model = factory(TuneSettingAttribute::class)->make([]);
$model->ordering = "fourth";
$this->assertFalse($model->validate());
}
}

View File

@@ -0,0 +1,378 @@
<?php
namespace Laravel5;
use Codeception\TestCase\Test;
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
use XaiCorp\AbcParser\Models\Laravel5\Person;
use XaiCorp\AbcParser\Models\Laravel5\Tune;
use XaiCorp\AbcParser\Models\Laravel5\TuneAttribute;
use XaiCorp\AbcParser\Models\Laravel5\TuneSetting;
use XaiCorp\AbcParser\Models\Laravel5\TuneSettingAttribute;
class TuneSettingTest 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' => '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()
{
$model = new TuneSetting();
$this->assertInstanceOf(TuneSetting::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
}
public function testMassAssignable()
{
$tune = factory(Tune::class)->create();
$data = [
'tune_id' => $tune->id,
'meter' => 'C',
'keysig' => 'C',
'filename' => 'filename',
'tempo' => '1/8=200',
'L' => '1/8',
'music' => '',
'parts' => 'abcbc'
];
$model = TuneSetting::create($data);
$this->assertInstanceOf(TuneSetting::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($data['meter'], $model->meter);
$this->assertEquals($data['keysig'], $model->keysig);
$this->assertEquals($data['filename'], $model->filename);
$this->assertEquals($data['tempo'], $model->tempo);
$this->assertEquals($data['L'], $model->L);
$this->assertEquals($data['music'], $model->music);
$this->assertEquals($data['parts'], $model->parts);
}
public function testFactory()
{
$model = factory(TuneSetting::class)->make([]);
$this->assertInstanceOf(TuneSetting::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertNotNull($model->tune_id);
$this->assertNotNull($model->meter);
$this->assertNotNull($model->keysig);
}
public function testValidationAppliedOnSave()
{
$model = factory(TuneSetting::class)->make([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->meter = 'NotType';
$this->assertFalse($model->save());
}
public function testCanGetTranscriberAttribute()
{
$value = 'C';
$model = factory(TuneSetting::class)->create([]);
$attr = factory(TuneSettingAttribute::class)->create([
'setting_id' => $model->id,
'type' => 'Transcriber',
'string' => $value,
]);
$model = $model->fresh();
$this->assertInstanceOf(TuneSetting::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($value, $model->Z[0]);
}
public function testSetTranscriberAttribute()
{
$values = ['Me', 'Womble2'];
$model = factory(TuneSetting::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->Z = $values;
$this->assertEquals($values[0], $model->Z[0]);
$this->assertEquals($values[1], $model->Z[1]);
}
public function testTranscriberAttributeSaves()
{
$values = ['Me', 'Womble2'];
$model = factory(TuneSetting::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->Z = $values;
$model->save();
$model = $model->fresh();
$this->assertEquals($values[0], $model->Z[0]);
$this->assertEquals($values[1], $model->Z[1]);
}
public function testCanGetNoteAttribute()
{
$value = 'A note';
$model = factory(TuneSetting::class)->create([]);
$attr = factory(TuneSettingAttribute::class)->create([
'setting_id' => $model->id,
'type' => 'Note',
'string' => $value,
]);
$model = $model->fresh();
$this->assertInstanceOf(TuneSetting::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($value, $model->N[0]);
}
public function testSetNoteAttribute()
{
$values = ['Me', 'Womble2'];
$model = factory(TuneSetting::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->N = $values;
$this->assertEquals($values[0], $model->N[0]);
$this->assertEquals($values[1], $model->N[1]);
}
public function testNoteAttributeSaves()
{
$values = ['Me', 'Womble2'];
$model = factory(TuneSetting::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->N = $values;
$model->save();
$model = $model->fresh();
$this->assertEquals($values[0], $model->N[0]);
$this->assertEquals($values[1], $model->N[1]);
}
public function testCanGetDiscographyAttribute()
{
$value = 'A recording';
$model = factory(TuneSetting::class)->create([]);
$attr = factory(TuneSettingAttribute::class)->create([
'setting_id' => $model->id,
'type' => 'Discography',
'string' => $value,
]);
$model = $model->fresh();
$this->assertInstanceOf(TuneSetting::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($value, $model->D[0]);
}
public function testSetDiscographyAttribute()
{
$values = ['Me', 'Womble2'];
$model = factory(TuneSetting::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->D = $values;
$this->assertEquals($values[0], $model->D[0]);
$this->assertEquals($values[1], $model->D[1]);
}
public function testDiscographyAttributeSaves()
{
$values = ['Me', 'Womble2'];
$model = factory(TuneSetting::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->D = $values;
$model->save();
$model = $model->fresh();
$this->assertEquals($values[0], $model->D[0]);
$this->assertEquals($values[1], $model->D[1]);
}
public function testCanGetSourceAttribute()
{
$value = 'A feel';
$model = factory(TuneSetting::class)->create([]);
$attr = factory(TuneSettingAttribute::class)->create([
'setting_id' => $model->id,
'type' => 'Source',
'string' => $value,
]);
$model = $model->fresh();
$this->assertInstanceOf(TuneSetting::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($value, $model->S[0]);
}
public function testSetSourceAttribute()
{
$values = ['Me', 'Womble2'];
$model = factory(TuneSetting::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->S = $values;
$this->assertEquals($values[0], $model->S[0]);
$this->assertEquals($values[1], $model->S[1]);
}
public function testSourceAttributeSaves()
{
$values = ['Me', 'Womble2'];
$model = factory(TuneSetting::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->S = $values;
$model->save();
$model = $model->fresh();
$this->assertEquals($values[0], $model->S[0]);
$this->assertEquals($values[1], $model->S[1]);
}
public function testCanGetWordAttribute()
{
$value = 'A feel';
$model = factory(TuneSetting::class)->create([]);
$attr = factory(TuneSettingAttribute::class)->create([
'setting_id' => $model->id,
'type' => 'Word',
'string' => $value,
]);
$model = $model->fresh();
$this->assertInstanceOf(TuneSetting::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($value, $model->W[0]);
}
public function testSetWordAttribute()
{
$values = ['Me', 'Womble2'];
$model = factory(TuneSetting::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->W = $values;
$this->assertEquals($values[0], $model->W[0]);
$this->assertEquals($values[1], $model->W[1]);
}
public function testWordAttributeSaves()
{
$values = ['Me', 'Womble2'];
$model = factory(TuneSetting::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->W = $values;
$model->save();
$model = $model->fresh();
$this->assertEquals($values[0], $model->W[0]);
$this->assertEquals($values[1], $model->W[1]);
}
public function testCanGetBookAttribute()
{
$value = 'A feel';
$model = factory(TuneSetting::class)->create([]);
$attr = factory(TuneSettingAttribute::class)->create([
'setting_id' => $model->id,
'type' => 'Book',
'string' => $value,
]);
$model = $model->fresh();
$this->assertInstanceOf(TuneSetting::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($value, $model->B[0]);
}
public function testSetBookAttribute()
{
$values = ['Me', 'Womble2'];
$model = factory(TuneSetting::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->B = $values;
$this->assertEquals($values[0], $model->B[0]);
$this->assertEquals($values[1], $model->B[1]);
}
public function testBookAttributeSaves()
{
$values = ['Me', 'Womble2'];
$model = factory(TuneSetting::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->B = $values;
$model->save();
$model = $model->fresh();
$this->assertEquals($values[0], $model->B[0]);
$this->assertEquals($values[1], $model->B[1]);
}
}

View File

@@ -0,0 +1,319 @@
<?php
namespace Laravel5;
use Codeception\TestCase\Test;
use Aedart\Testing\Laravel\Traits\TestHelperTrait;
use XaiCorp\AbcParser\Models\Laravel5\Person;
use XaiCorp\AbcParser\Models\Laravel5\Tune;
use XaiCorp\AbcParser\Models\Laravel5\TuneAttribute;
class TuneTest 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' => '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()
{
$model = new Tune();
$this->assertInstanceOf(Tune::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
}
public function testMassAssignable()
{
$xId = 44;
$model = Tune::create([
'x_id' => $xId,
]);
$this->assertInstanceOf(Tune::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($xId, $model->x_id);
}
public function testFactory()
{
$model = factory(Tune::class)->make([]);
$this->assertInstanceOf(Tune::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertNotNull($model->x_id);
}
public function testCanGetTitleAttribute()
{
$title = 'Wombles Forever';
$model = factory(Tune::class)->create([]);
$attr = factory(TuneAttribute::class)->create([
'tune_id' => $model->id,
'type' => 'Title',
'string' => $title,
]);
$model = $model->fresh();
$this->assertInstanceOf(Tune::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($title, $model->T[0]);
}
public function testSetTitleAttribute()
{
$titles = ['Title1', 'Womble2'];
$model = factory(Tune::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->T = $titles;
$this->assertEquals($titles[0], $model->T[0]);
$this->assertEquals($titles[1], $model->T[1]);
}
public function testTitleAttributeSaves()
{
$titles = ['Title1', 'Womble2'];
$model = factory(Tune::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->T = $titles;
$model->save();
$model = $model->fresh();
$this->assertEquals($titles[0], $model->T[0]);
$this->assertEquals($titles[1], $model->T[1]);
}
public function testCanGetGroupAttribute()
{
$group = 'Flute';
$model = factory(Tune::class)->create([]);
$attr = factory(TuneAttribute::class)->create([
'tune_id' => $model->id,
'type' => 'Group',
'string' => $group,
]);
$model = $model->fresh();
$this->assertInstanceOf(Tune::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($group, $model->G[0]);
}
public function testSetGroupAttribute()
{
$groups = ['Flute', 'Oboe'];
$model = factory(Tune::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->G = $groups;
$this->assertEquals($groups[0], $model->G[0]);
$this->assertEquals($groups[1], $model->G[1]);
}
public function testGroupAttributeSaves()
{
$groups = ['Flute', 'Oboe'];
$model = factory(Tune::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->G = $groups;
$model->save();
$model = $model->fresh();
$this->assertEquals($groups[0], $model->G[0]);
$this->assertEquals($groups[1], $model->G[1]);
}
public function testCanGetOriginAttribute()
{
$origin = 'England';
$model = factory(Tune::class)->create([]);
$attr = factory(TuneAttribute::class)->create([
'tune_id' => $model->id,
'type' => 'Origin',
'string' => $origin,
]);
$model = $model->fresh();
$this->assertInstanceOf(Tune::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($origin, $model->O[0]);
}
public function testSetOriginAttribute()
{
$origins = ['England', 'Scotland'];
$model = factory(Tune::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->O = $origins;
$this->assertEquals($origins[0], $model->O[0]);
$this->assertEquals($origins[1], $model->O[1]);
}
public function testOriginAttributeSaves()
{
$origins = ['England', 'Scotland'];
$model = factory(Tune::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->O = $origins;
$model->save();
$model = $model->fresh();
$this->assertEquals($origins[0], $model->O[0]);
$this->assertEquals($origins[1], $model->O[1]);
}
public function testCanGetRhythmAttribute()
{
$rhythm = 'Reel';
$model = factory(Tune::class)->create([]);
$attr = factory(TuneAttribute::class)->create([
'tune_id' => $model->id,
'type' => 'Rhythm',
'string' => $rhythm,
]);
$model = $model->fresh();
$this->assertInstanceOf(Tune::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($rhythm, $model->R[0]);
}
public function testSetRhythmAttribute()
{
$rhythms = ['Reel', 'March'];
$model = factory(Tune::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->R = $rhythms;
$this->assertEquals($rhythms[0], $model->R[0]);
$this->assertEquals($rhythms[1], $model->R[1]);
}
public function testRhythmAttributeSaves()
{
$rhythms = ['England', 'Scotland'];
$model = factory(Tune::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->R = $rhythms;
$model->save();
$model = $model->fresh();
$this->assertEquals($rhythms[0], $model->R[0]);
$this->assertEquals($rhythms[1], $model->R[1]);
}
public function testCanGetHistoryAttribute()
{
$history = 'England';
$model = factory(Tune::class)->create([]);
$attr = factory(TuneAttribute::class)->create([
'tune_id' => $model->id,
'type' => 'History',
'string' => $history,
]);
$model = $model->fresh();
$this->assertInstanceOf(Tune::class, $model);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$this->assertEquals($history, $model->H[0]);
}
public function testSetHistoryAttribute()
{
$history = ['some ', 'lines'];
$model = factory(Tune::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->H = $history;
$this->assertEquals($history[0], $model->H[0]);
$this->assertEquals($history[1], $model->H[1]);
}
public function testHistoryAttributeSaved()
{
$history = ['some ', 'lines'];
$model = factory(Tune::class)->create([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->H = $history;
$model->save();
$model = $model->fresh();
$this->assertEquals($history[0], $model->H[0]);
$this->assertEquals($history[1], $model->H[1]);
}
public function testValidationAppliedOnSave()
{
$model = factory(Tune::class)->make([]);
$this->assertEmpty($model->getMessages(), json_encode($model->getMessages()));
$model->x_id = 'NotType';
$this->assertFalse($model->save());
}
}

View File

@@ -0,0 +1,56 @@
<?php
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(\XaiCorp\AbcParser\Models\Laravel5\Collection::class, function (Faker\Generator $faker) {
return [
'name' => $faker->name,
];
});
$factory->define(\XaiCorp\AbcParser\Models\Laravel5\Tune::class, function (Faker\Generator $faker) {
return [
'x_id' => $faker->numberBetween(1, 10),
];
});
$factory->define(\XaiCorp\AbcParser\Models\Laravel5\Person::class, function (Faker\Generator $faker) {
return [
'name' => $faker->name,
'email'=> $faker->safeEmail,
];
});
$factory->define(\XaiCorp\AbcParser\Models\Laravel5\TuneAttribute::class, function (Faker\Generator $faker) {
$types = \XaiCorp\AbcParser\Models\Laravel5\TuneAttribute::getTypes();
return [
'tune_id' => function () {
return factory(\XaiCorp\AbcParser\Models\Laravel5\Tune::class)->create()->id;
},
'type' => $types[random_int(0, count($types)-1)],
'string' => $faker->words(3, true),
'ordering' => $faker->numberBetween(1, 5),
];
});
$factory->define(\XaiCorp\AbcParser\Models\Laravel5\CollectionAttribute::class, function (Faker\Generator $faker) {
$types = \XaiCorp\AbcParser\Models\Laravel5\CollectionAttribute::getTypes();
return [
'collection_id' => function () {
return factory(\XaiCorp\AbcParser\Models\Laravel5\Collection::class)->create()->id;
},
'type' => $types[random_int(0, count($types)-1)],
'string' => $faker->words(3, true),
'ordering' => $faker->numberBetween(1, 5),
];
});

View File

@@ -0,0 +1,24 @@
<?php
$factory->define(\XaiCorp\AbcParser\Models\Laravel5\TuneSetting::class, function (Faker\Generator $faker) {
return [
'tune_id' => function () {
return factory(\XaiCorp\AbcParser\Models\Laravel5\Tune::class)->create()->id;
},
'meter' => 'C',
'keysig' => '6/8',
];
});
$factory->define(\XaiCorp\AbcParser\Models\Laravel5\TuneSettingAttribute::class, function (Faker\Generator $faker) {
$types = \XaiCorp\AbcParser\Models\Laravel5\TuneSettingAttribute::getTypes();
return [
'setting_id' => function () {
return factory(\XaiCorp\AbcParser\Models\Laravel5\TuneSetting::class)->create()->id;
},
'type' => $types[random_int(0, count($types)-1)],
'string' => $faker->words(3, true),
'ordering' => $faker->numberBetween(1, 5),
];
});