Skip to content

Commit

Permalink
#111. Add more coverage on Json helper
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Jun 11, 2018
1 parent aabc035 commit 4c45da6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
10 changes: 10 additions & 0 deletions tests/_data/ArticleFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,21 @@ public static function createAndGet() : Article
return $article;
}

public static function getCollection($params)
{
return Article::where($params)->get();
}

/**
* @param $id
*/
public static function delete($id) : void
{
Article::destroy($id);
}

public static function truncate()
{
Article::truncate();
}
}
2 changes: 1 addition & 1 deletion tests/unit/blocks/MigrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function setUp()
]
];
$this->gen->objectName = 'Article';
$this->gen->version = 'v2';
$this->gen->version = self::MODULE_NAME;
$this->gen->modulesDir = DirsInterface::MODULES_DIR;
$this->gen->middlewareDir = DirsInterface::MIDDLEWARE_DIR;
$this->gen->migrationsDir = DirsInterface::MIGRATIONS_DIR;
Expand Down
1 change: 1 addition & 0 deletions tests/unit/controllers/GeneratorTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use rjapi\controllers\GeneratorTrait;
use rjapi\types\ConsoleInterface;
use rjapi\types\DirsInterface;
use rjapitest\unit\TestCase;

class GeneratorTraitTest extends TestCase
Expand Down
29 changes: 13 additions & 16 deletions tests/unit/helpers/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
use League\Fractal\Resource\Item;
use Modules\V2\Entities\Article;
use Modules\V2\Http\Middleware\ArticleMiddleware;
use PHPUnit\Framework\Constraint\IsType;
use PHPUnit_Framework_MockObject_MockObject;
use rjapi\extension\BaseFormRequest;
use rjapi\extension\BaseModel;
use rjapi\extension\JSONApiInterface;
use rjapi\helpers\Json;
use rjapi\types\RamlInterface;
use rjapitest\_data\ArticleFixture;
use rjapitest\unit\TestCase;

/**
Expand Down Expand Up @@ -146,20 +148,15 @@ public function it_encodes_decodes_json()
], Json::decode('{"title":"Foo Bar Baz"}'));
}

// /**
// * @test
// */
// public function it_gets_relations()
// {
// $collection = new Collection();
//// $items = new class extends \ArrayAccessible {
////
//// };
//// $items->offsetSet(0, 'title')
// $collection->add([
// 'title' => 'Foo Bar Baz'
// ]);
// $rels = Json::getRelations($collection, 'article');
// print_r($rels);
// }
/**
* @test
*/
public function it_gets_relations()
{
ArticleFixture::createAndGet();
$articles = ArticleFixture::getCollection([['topic_id', '>=', 1]]);
$rels = Json::getRelations($articles, 'article');
$this->assertInternalType(IsType::TYPE_ARRAY, $rels);
ArticleFixture::truncate();
}
}

0 comments on commit 4c45da6

Please sign in to comment.