Skip to content

Commit

Permalink
#111. Add more coverage on Routes/BaseFormRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Jun 5, 2018
1 parent adaeceb commit 8454281
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/blocks/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function setCodeState($generator)
$this->generator = $generator;
}

public function create()
public function create() : void
{
$this->setRoutes();
$isCreated = false;
Expand All @@ -53,7 +53,7 @@ public function create()
}
}

private function setRoutes()
private function setRoutes() : void
{
$this->setTag();
$this->setComment(DefaultInterface::ROUTES_START, 0);
Expand Down
58 changes: 58 additions & 0 deletions tests/unit/blocks/RouterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace rjapitest\unit\blocks;

use rjapi\blocks\ContentManager;
use rjapi\blocks\Routes;
use rjapi\blocks\RoutesTrait;
use rjapi\RJApiGenerator;
use rjapi\types\DirsInterface;
use rjapi\types\RamlInterface;
use rjapitest\unit\TestCase;
use Symfony\Component\Yaml\Yaml;

/**
* Class ConfigTest
* @package rjapitest\unit\blocks
* @property Routes router
*/
class RouterTest extends TestCase
{
/** @var RJApiGenerator $gen */
private $gen;
private $router;

public function setUp()
{
parent::setUp();
$this->gen = new RJApiGenerator();
$this->gen->modulesDir = DirsInterface::MODULES_DIR;
$this->gen->controllersDir = DirsInterface::CONTROLLERS_DIR;
$this->gen->httpDir = DirsInterface::HTTP_DIR;
$this->gen->version = self::MODULE_NAME;
$ramlData = Yaml::parse(file_get_contents(__DIR__ . '/../../functional/raml/articles.raml'));
$this->gen->types = $ramlData[RamlInterface::RAML_KEY_TYPES];
$this->gen->objectProps = [
'type' => 'Type',
'id' => 'ID',
'attributes' => 'ArticleAttributes',
'relationships' => [
'type' => 'TagRelationships[] | TopicRelationships',
]
];
$this->router = new Routes($this->gen);
$this->router->setCodeState($this->gen);
}

/**
* @test
*/
public function it_creates_routes()
{
$this->router->create();
$this->assertArraySubset([
ContentManager::class => ContentManager::class,
RoutesTrait::class => RoutesTrait::class,
], class_uses($this->router));
}
}
53 changes: 53 additions & 0 deletions tests/unit/extension/BaseFormRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace rjapitest\unit\extensions;


use Illuminate\Support\Facades\Request;
use PHPUnit\Framework\Constraint\IsType;
use rjapi\extension\BaseFormRequest;
use rjapi\extension\CustomSql;
use rjapitest\unit\TestCase;

/**
* Class CustomSqlTest
* @package rjapitest\unit\extensions
*
* @property BaseFormRequest baseFormRequest
*/
class BaseFormRequestTest extends TestCase
{
private $baseFormRequest;

public function setUp()
{
parent::setUp();
$this->baseFormRequest = new BaseFormRequest();
}

/**
* @test
*/
public function it_handles_request()
{
$this->assertInstanceOf(Request::class, $this->baseFormRequest->handle(new Request(), function($request) {
return $request;
}));
}

/**
* @test
*/
public function it_gets_query()
{
$this->assertInternalType(IsType::TYPE_ARRAY, $this->baseFormRequest->rules());
}

/**
* @test
*/
public function it_get_bindings()
{
$this->assertInternalType(IsTYpe::TYPE_ARRAY, $this->baseFormRequest->relations());
}
}

0 comments on commit 8454281

Please sign in to comment.