Skip to content

Commit

Permalink
#111. Add MethodOptionsTest/ConfigOptionsTest + improve others + file…
Browse files Browse the repository at this point in the history
…s unlink
  • Loading branch information
arthurkushman committed Jun 3, 2018
1 parent 7d75938 commit 0facfc8
Show file tree
Hide file tree
Showing 9 changed files with 442 additions and 330 deletions.
553 changes: 274 additions & 279 deletions clover.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/blocks/MigrationsAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private function setId($attrVal, $attrKey, $type): void
*/
protected function createMigrationFile(string $migrationName): void
{
$migrationMask = date(self::PATTERN_TIME, time()) . random_int(10, 99);
$migrationMask = date(self::PATTERN_TIME) . random_int(10, 99);
$file = $this->generator->formatMigrationsPath() . $migrationMask . PhpInterface::UNDERSCORE .
$migrationName . PhpInterface::PHP_EXT;

Expand Down
23 changes: 8 additions & 15 deletions src/helpers/ConfigOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,47 +150,40 @@ public function setStateMachine(bool $isStateMachine)
/**
* @return bool
*/
public function isStateMachine()
public function isStateMachine() : bool
{
return $this->isStateMachine;
}

/**
* @return boolean
*/
public function isSpellCheck()
public function isSpellCheck() : bool
{
return $this->spellCheck;
}

/**
* @param boolean $spellCheck
*/
public function setSpellCheck($spellCheck)
public function setSpellCheck($spellCheck) : void
{
$this->spellCheck = $spellCheck;
}

public function setBitMask($isBitwise)
/**
* @param bool $isBitwise
*/
public function setBitMask($isBitwise) : void
{
$this->isBitWise = $isBitwise;
}

public function isBitMask()
public function isBitMask() : bool
{
return $this->isBitWise;
}

public function isBitMaskHidden()
{
return $this->hiddenBitMask;
}

public function setBitMaskHidden($isHidden)
{
$this->hiddenBitMask = $isHidden;
}

/**
* @return bool
*/
Expand Down
16 changes: 8 additions & 8 deletions src/helpers/MethodOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,63 @@ class MethodOptions
/**
* @return string
*/
public function getModifier()
public function getModifier() : string
{
return $this->modifier;
}

/**
* @param string $modifier
*/
public function setModifier($modifier)
public function setModifier($modifier) : void
{
$this->modifier = $modifier;
}

/**
* @return string
*/
public function getName()
public function getName() : string
{
return $this->name;
}

/**
* @param string $name
*/
public function setName($name)
public function setName($name) : void
{
$this->name = $name;
}

/**
* @return string
*/
public function getReturnType()
public function getReturnType() : string
{
return $this->returnType;
}

/**
* @param string $returnType
*/
public function setReturnType($returnType)
public function setReturnType($returnType) : void
{
$this->returnType = $returnType;
}

/**
* @return boolean
*/
public function isStatic()
public function isStatic() : bool
{
return $this->isStatic;
}

/**
* @param boolean $isStatic
*/
public function setIsStatic($isStatic)
public function setIsStatic($isStatic) : void
{
$this->isStatic = $isStatic;
}
Expand Down
15 changes: 10 additions & 5 deletions tests/unit/_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
require_once __DIR__ . '/../../vendor/laravel/framework/src/Illuminate/Foundation/helpers.php';

spl_autoload_register(
function($class)
{
if(file_exists(str_replace('\\', '/', str_replace('App\\', '', $class)) . '.php'))
{
function ($class) {
if (file_exists(str_replace('\\', '/', str_replace('App\\', '', $class)) . '.php')) {
require_once str_replace('\\', '/', str_replace('App\\', '', $class)) . '.php';
}
}
);
);

register_shutdown_function(function () {
$files = glob('./tests/_output/*Test*.php');
foreach ($files as $file) {
unlink($file);
}
});
2 changes: 1 addition & 1 deletion tests/unit/blocks/EntitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function setUp()
public function it_creates_middleware_and_entity()
{
// create Middleware for further entities to run
$this->middleware->createEntity('./tests/_output/', 'Middleware');
$this->middleware->createEntity(self::DIR_OUTPUT, 'Middleware');
$this->assertTrue(file_exists(self::DIR_OUTPUT . 'ArticleTestMiddleware.php'));
require_once __DIR__ . '/../../_output/ArticleTestMiddleware.php';
$articleMiddleware = new ArticleTestMiddleware();
Expand Down
78 changes: 57 additions & 21 deletions tests/unit/blocks/MigrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,44 @@
/**
* Class MigrationsTest
* @package rjapitest\unit\blocks
*
* @property Migrations migrations
* @property RJApiGenerator gen
*/
class MigrationsTest extends TestCase
{
private $migrations;
private $gen;

/**
* @throws \ReflectionException
*/
public function setUp()
{
parent::setUp();
/** @var RJApiGenerator|PHPUnit_Framework_MockObject_MockObject $gen */
$gen = $this->createMock(RJApiGenerator::class);
$gen->method('options')->willReturn([
$this->gen = $this->createMock(RJApiGenerator::class);
$this->gen->method('options')->willReturn([
ConsoleInterface::OPTION_REGENERATE => 1,
ConsoleInterface::OPTION_MIGRATIONS => 1,
]);
$gen->types = [
'ID' => [
'type' => 'integer',
$this->gen->method('formatMigrationsPath')->willReturn(self::DIR_OUTPUT);
$this->gen->types = [
'ID' => [
'type' => 'integer',
'required' => 'true',
'maximum' => 20,
'maximum' => 20,
],
'ArticleAttributes' => [
'description' => 'Article attributes description',
'type' => 'object',
'properties' => [
'type' => 'object',
'properties' => [
'title' => [
'required' => true,
'type' => 'string',
'required' => true,
'type' => 'string',
'minLength' => 16,
'maxLength' => 256,
'facets' => [
'facets' => [
'index' => [
'idx_title' => 'index'
]
Expand All @@ -52,20 +59,20 @@ public function setUp()
]
]
];
$gen->objectProps = [
'type' => 'Type',
'id' => 'ID',
'attributes' => 'ArticleAttributes',
$this->gen->objectProps = [
'type' => 'Type',
'id' => 'ID',
'attributes' => 'ArticleAttributes',
'relationships' => [
'type' => 'TagRelationships[] | TopicRelationships',
]
];
$gen->objectName = 'Article';
$gen->version = 'v2';
$gen->modulesDir = DirsInterface::MODULES_DIR;
$gen->middlewareDir = DirsInterface::MIDDLEWARE_DIR;
$gen->migrationsDir = DirsInterface::MIGRATIONS_DIR;
$this->migrations = new Migrations($gen);
$this->gen->objectName = 'Article';
$this->gen->version = 'v2';
$this->gen->modulesDir = DirsInterface::MODULES_DIR;
$this->gen->middlewareDir = DirsInterface::MIDDLEWARE_DIR;
$this->gen->migrationsDir = DirsInterface::MIGRATIONS_DIR;
$this->migrations = new Migrations($this->gen);
}

/**
Expand All @@ -77,4 +84,33 @@ public function it_creates_entity()
$this->migrations->create();
$this->migrations->createPivot();
}

/**
* @test
*/
public function it_resets_content()
{
$this->gen->isMerge = true;
$this->gen->diffTypes = [
'ArticleAttributes' => [
'title' => [
'required' => 'true',
'type' => 'string',
'minLength' => 32,
'maxLength' => 128,
]
]
];
$this->migrations = new Migrations($this->gen);
$this->migrations->create();
$this->assertNotEmpty(glob(self::DIR_OUTPUT . '*add_column_title_to_article.php'));
}

public static function tearDownAfterClass()
{
$files = glob(self::DIR_OUTPUT . '*add_column_title_to_article.php');
foreach ($files as $file) {
unlink($file);
}
}
}
24 changes: 24 additions & 0 deletions tests/unit/helpers/ConfigOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,29 @@ public function it_sets_configuration_options()

$this->configOptions->setIsJwtAction(true);
$this->assertTrue($this->configOptions->getIsJwtAction());

$this->configOptions->setStateMachine(true);
$this->assertTrue($this->configOptions->isStateMachine());

$this->configOptions->setSpellCheck(true);
$this->assertTrue($this->configOptions->isSpellCheck());

$this->configOptions->setBitMask(true);
$this->assertTrue($this->configOptions->isBitMask());

$this->configOptions->setIsCached(true);
$this->assertTrue($this->configOptions->isCached());

$this->configOptions->setIsXFetch(true);
$this->assertTrue($this->configOptions->isXFetch());

$this->configOptions->setCacheTtl(3600);
$this->assertEquals(3600, $this->configOptions->getCacheTtl());

$this->configOptions->setCacheBeta(1.1);
$this->assertEquals(1.1, $this->configOptions->getCacheBeta());

$this->configOptions->setCalledMethod('index');
$this->assertEquals('index', $this->configOptions->getCalledMethod());
}
}
59 changes: 59 additions & 0 deletions tests/unit/helpers/MethodOptionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Created by PhpStorm.
* User: arthurkushman
* Date: 03.06.18
* Time: 14:48
*/

namespace rjapitest\unit\helpers;


use rjapi\helpers\MethodOptions;
use rjapi\types\MiddlewareInterface;
use rjapi\types\PhpInterface;
use rjapitest\unit\TestCase;

/**
* Class MethodOptionsTest
* @package rjapitest\unit\helpers
*
* @property MethodOptions methodOptions
*/
class MethodOptionsTest extends TestCase
{
private $methodOptions;

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

/**
* @test
*/
public function it_sets_and_gets_options()
{
$this->methodOptions->setModifier(PhpInterface::PHP_MODIFIER_PRIVATE);
$this->assertEquals(PhpInterface::PHP_MODIFIER_PRIVATE, $this->methodOptions->getModifier());

$this->methodOptions->setName('foo');
$this->assertEquals('foo', $this->methodOptions->getName());

$this->methodOptions->setReturnType('bool');
$this->assertEquals('bool', $this->methodOptions->getReturnType());

$this->methodOptions->setIsStatic(true);
$this->assertTrue($this->methodOptions->isStatic());

$this->methodOptions->setParams([
MiddlewareInterface::METHOD_PARAM_REQUEST,
PhpInterface::CLASS_CLOSURE => MiddlewareInterface::METHOD_PARAM_NEXT,
]);
$this->assertArraySubset([
MiddlewareInterface::METHOD_PARAM_REQUEST,
PhpInterface::CLASS_CLOSURE => MiddlewareInterface::METHOD_PARAM_NEXT,
], $this->methodOptions->getParams());
}
}

0 comments on commit 0facfc8

Please sign in to comment.