Skip to content

Commit

Permalink
#111. Add coverage on BitMask extension + bug fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed May 30, 2018
1 parent 215583e commit 0545590
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 81 deletions.
111 changes: 49 additions & 62 deletions clover.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1527575014">
<project timestamp="1527575014">
<coverage generated="1527710875">
<project timestamp="1527710875">
<package name="rjapi">
<file name="/srv/raml-json-api/src/RJApiGenerator.php">
<class name="rjapi\RJApiGenerator" namespace="rjapi">
Expand Down Expand Up @@ -1717,53 +1717,50 @@
<metrics loc="268" ncloc="208" classes="1" methods="14" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="127" coveredstatements="0" elements="141" coveredelements="0"/>
</file>
</package>
<package name="rjapi\exception">
<package name="rjapi\exceptions">
<file name="/srv/raml-json-api/src/exceptions/AttributesException.php">
<class name="rjapi\exception\AttributesException" namespace="rjapi\exception">
<class name="rjapi\exceptions\AttributesException" namespace="rjapi\exceptions">
<metrics complexity="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
</class>
<metrics loc="5" ncloc="5" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
</file>
<file name="/srv/raml-json-api/src/exceptions/BaseException.php">
<class name="rjapi\exception\BaseException" namespace="rjapi\exception">
<metrics complexity="2" methods="2" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="12" coveredstatements="0" elements="14" coveredelements="0"/>
<class name="rjapi\exceptions\BaseException" namespace="rjapi\exceptions">
<metrics complexity="2" methods="2" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="9" coveredstatements="2" elements="11" coveredelements="3"/>
</class>
<line num="9" type="method" name="__construct" visibility="public" complexity="1" crap="2" count="0"/>
<line num="10" type="stmt" count="0"/>
<line num="11" type="stmt" count="0"/>
<line num="12" type="stmt" count="0"/>
<line num="9" type="method" name="__construct" visibility="public" complexity="1" crap="1" count="1"/>
<line num="11" type="stmt" count="1"/>
<line num="12" type="stmt" count="1"/>
<line num="14" type="method" name="__toString" visibility="public" complexity="1" crap="2" count="0"/>
<line num="15" type="stmt" count="0"/>
<line num="16" type="stmt" count="0"/>
<line num="17" type="stmt" count="0"/>
<line num="18" type="stmt" count="0"/>
<line num="19" type="stmt" count="0"/>
<line num="20" type="stmt" count="0"/>
<line num="21" type="stmt" count="0"/>
<line num="22" type="stmt" count="0"/>
<line num="23" type="stmt" count="0"/>
<metrics loc="23" ncloc="23" classes="1" methods="2" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="12" coveredstatements="0" elements="14" coveredelements="0"/>
<metrics loc="23" ncloc="23" classes="1" methods="2" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="9" coveredstatements="2" elements="11" coveredelements="3"/>
</file>
<file name="/srv/raml-json-api/src/exceptions/DirectoryException.php">
<class name="rjapi\exception\DirectoryException" namespace="rjapi\exception">
<class name="rjapi\exceptions\DirectoryException" namespace="rjapi\exceptions">
<metrics complexity="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
</class>
<metrics loc="6" ncloc="6" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
</file>
<file name="/srv/raml-json-api/src/exceptions/MethodNotFoundException.php">
<class name="rjapi\exception\MethodNotFoundException" namespace="rjapi\exception">
<class name="rjapi\exceptions\MethodNotFoundException" namespace="rjapi\exceptions">
<metrics complexity="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
</class>
<metrics loc="5" ncloc="5" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
</file>
<file name="/srv/raml-json-api/src/exceptions/ModelException.php">
<class name="rjapi\exception\ModelException" namespace="rjapi\exception">
<class name="rjapi\exceptions\ModelException" namespace="rjapi\exceptions">
<metrics complexity="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
</class>
<metrics loc="6" ncloc="6" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
</file>
<file name="/srv/raml-json-api/src/exceptions/SchemaException.php">
<class name="rjapi\exception\SchemaException" namespace="rjapi\exception">
<class name="rjapi\exceptions\SchemaException" namespace="rjapi\exceptions">
<metrics complexity="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
</class>
<metrics loc="5" ncloc="5" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
Expand Down Expand Up @@ -2119,34 +2116,24 @@
</file>
<file name="/srv/raml-json-api/src/extension/BitMask.php">
<class name="rjapi\extension\BitMask" namespace="rjapi\extension">
<metrics complexity="8" methods="5" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="20" coveredstatements="0" elements="25" coveredelements="0"/>
<metrics complexity="8" methods="5" coveredmethods="5" conditionals="0" coveredconditionals="0" statements="10" coveredstatements="10" elements="15" coveredelements="15"/>
</class>
<line num="18" type="method" name="__construct" visibility="public" complexity="2" crap="6" count="0"/>
<line num="19" type="stmt" count="0"/>
<line num="20" type="stmt" count="0"/>
<line num="21" type="stmt" count="0"/>
<line num="22" type="stmt" count="0"/>
<line num="23" type="stmt" count="0"/>
<line num="28" type="method" name="isEnabled" visibility="public" complexity="1" crap="2" count="0"/>
<line num="29" type="stmt" count="0"/>
<line num="30" type="stmt" count="0"/>
<line num="31" type="stmt" count="0"/>
<line num="36" type="method" name="getField" visibility="public" complexity="1" crap="2" count="0"/>
<line num="37" type="stmt" count="0"/>
<line num="38" type="stmt" count="0"/>
<line num="39" type="stmt" count="0"/>
<line num="41" type="method" name="getFlags" visibility="public" complexity="2" crap="6" count="0"/>
<line num="42" type="stmt" count="0"/>
<line num="43" type="stmt" count="0"/>
<line num="44" type="stmt" count="0"/>
<line num="45" type="stmt" count="0"/>
<line num="46" type="stmt" count="0"/>
<line num="47" type="stmt" count="0"/>
<line num="49" type="method" name="isHidden" visibility="public" complexity="2" crap="6" count="0"/>
<line num="50" type="stmt" count="0"/>
<line num="51" type="stmt" count="0"/>
<line num="52" type="stmt" count="0"/>
<metrics loc="52" ncloc="41" classes="1" methods="5" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="20" coveredstatements="0" elements="25" coveredelements="0"/>
<line num="17" type="method" name="__construct" visibility="public" complexity="2" crap="2" count="1"/>
<line num="19" type="stmt" count="1"/>
<line num="20" type="stmt" count="1"/>
<line num="21" type="stmt" count="1"/>
<line num="22" type="stmt" count="1"/>
<line num="27" type="method" name="isEnabled" visibility="public" complexity="1" crap="1" count="1"/>
<line num="29" type="stmt" count="1"/>
<line num="35" type="method" name="getField" visibility="public" complexity="1" crap="1" count="1"/>
<line num="37" type="stmt" count="1"/>
<line num="44" type="method" name="getFlags" visibility="public" complexity="2" crap="2" count="1"/>
<line num="46" type="stmt" count="1"/>
<line num="47" type="stmt" count="1"/>
<line num="49" type="stmt" count="1"/>
<line num="52" type="method" name="isHidden" visibility="public" complexity="2" crap="2" count="1"/>
<line num="54" type="stmt" count="1"/>
<metrics loc="55" ncloc="41" classes="1" methods="5" coveredmethods="5" conditionals="0" coveredconditionals="0" statements="10" coveredstatements="10" elements="15" coveredelements="15"/>
</file>
<file name="/srv/raml-json-api/src/extension/BitMaskTrait.php">
<class name="BitMaskTrait" namespace="rjapi\extension" fullPackage="rjapi" package="rjapi">
Expand Down Expand Up @@ -2697,14 +2684,14 @@
</file>
<file name="/srv/raml-json-api/src/helpers/Json.php">
<class name="rjapi\helpers\Json" namespace="rjapi\helpers">
<metrics complexity="35" methods="13" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="73" coveredstatements="8" elements="86" coveredelements="8"/>
<metrics complexity="35" methods="13" coveredmethods="4" conditionals="0" coveredconditionals="0" statements="73" coveredstatements="18" elements="86" coveredelements="22"/>
</class>
<line num="26" type="method" name="getAttributes" visibility="public" complexity="2" crap="6" count="0"/>
<line num="28" type="stmt" count="0"/>
<line num="36" type="method" name="getRelationships" visibility="public" complexity="2" crap="6" count="0"/>
<line num="38" type="stmt" count="0"/>
<line num="46" type="method" name="getData" visibility="public" complexity="2" crap="6" count="0"/>
<line num="48" type="stmt" count="0"/>
<line num="26" type="method" name="getAttributes" visibility="public" complexity="2" crap="2" count="1"/>
<line num="28" type="stmt" count="1"/>
<line num="36" type="method" name="getRelationships" visibility="public" complexity="2" crap="2" count="1"/>
<line num="38" type="stmt" count="1"/>
<line num="46" type="method" name="getData" visibility="public" complexity="2" crap="2" count="1"/>
<line num="48" type="stmt" count="1"/>
<line num="56" type="method" name="getRelations" visibility="public" complexity="5" crap="30" count="0"/>
<line num="58" type="stmt" count="0"/>
<line num="59" type="stmt" count="0"/>
Expand All @@ -2717,15 +2704,15 @@
<line num="69" type="stmt" count="0"/>
<line num="70" type="stmt" count="0"/>
<line num="76" type="stmt" count="0"/>
<line num="85" type="method" name="outputErrors" visibility="public" complexity="3" crap="12" count="0"/>
<line num="87" type="stmt" count="0"/>
<line num="88" type="stmt" count="0"/>
<line num="89" type="stmt" count="0"/>
<line num="92" type="stmt" count="0"/>
<line num="93" type="stmt" count="0"/>
<line num="85" type="method" name="outputErrors" visibility="public" complexity="3" crap="3.14" count="1"/>
<line num="87" type="stmt" count="1"/>
<line num="88" type="stmt" count="1"/>
<line num="89" type="stmt" count="1"/>
<line num="92" type="stmt" count="1"/>
<line num="93" type="stmt" count="1"/>
<line num="94" type="stmt" count="0"/>
<line num="95" type="stmt" count="0"/>
<line num="97" type="stmt" count="0"/>
<line num="97" type="stmt" count="1"/>
<line num="104" type="method" name="outputSerializedRelations" visibility="public" complexity="1" crap="2" count="0"/>
<line num="106" type="stmt" count="0"/>
<line num="107" type="stmt" count="0"/>
Expand Down Expand Up @@ -2760,8 +2747,8 @@
<line num="167" type="stmt" count="0"/>
<line num="168" type="stmt" count="0"/>
<line num="169" type="stmt" count="0"/>
<line num="177" type="method" name="encode" visibility="public" complexity="1" crap="2" count="0"/>
<line num="179" type="stmt" count="0"/>
<line num="177" type="method" name="encode" visibility="public" complexity="1" crap="1" count="1"/>
<line num="179" type="stmt" count="1"/>
<line num="186" type="method" name="decode" visibility="public" complexity="1" crap="2" count="0"/>
<line num="188" type="stmt" count="0"/>
<line num="196" type="method" name="getSelectedData" visibility="private" complexity="3" crap="12" count="0"/>
Expand All @@ -2785,7 +2772,7 @@
<line num="237" type="stmt" count="0"/>
<line num="238" type="stmt" count="0"/>
<line num="241" type="stmt" count="0"/>
<metrics loc="241" ncloc="164" classes="1" methods="13" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="73" coveredstatements="8" elements="86" coveredelements="8"/>
<metrics loc="241" ncloc="164" classes="1" methods="13" coveredmethods="4" conditionals="0" coveredconditionals="0" statements="73" coveredstatements="18" elements="86" coveredelements="22"/>
</file>
<file name="/srv/raml-json-api/src/helpers/Jwt.php">
<class name="rjapi\helpers\Jwt" namespace="rjapi\helpers">
Expand Down Expand Up @@ -2993,6 +2980,6 @@
<file name="/srv/raml-json-api/src/types/RoutesInterface.php">
<metrics loc="14" ncloc="14" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
</file>
<metrics files="71" loc="6671" ncloc="5006" classes="46" methods="343" coveredmethods="104" conditionals="0" coveredconditionals="0" statements="2263" coveredstatements="582" elements="2606" coveredelements="686"/>
<metrics files="71" loc="6674" ncloc="5006" classes="46" methods="343" coveredmethods="114" conditionals="0" coveredconditionals="0" statements="2250" coveredstatements="604" elements="2593" coveredelements="718"/>
</project>
</coverage>
2 changes: 1 addition & 1 deletion src/exceptions/AttributesException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace rjapi\exception;
namespace rjapi\exceptions;

class AttributesException extends BaseException
{
Expand Down
2 changes: 1 addition & 1 deletion src/exceptions/BaseException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace rjapi\exception;
namespace rjapi\exceptions;

use rjapi\helpers\Json;

Expand Down
2 changes: 1 addition & 1 deletion src/exceptions/DirectoryException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace rjapi\exception;
namespace rjapi\exceptions;

class DirectoryException extends BaseException
{
Expand Down
2 changes: 1 addition & 1 deletion src/exceptions/MethodNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace rjapi\exception;
namespace rjapi\exceptions;

class MethodNotFoundException extends BaseException
{
Expand Down
2 changes: 1 addition & 1 deletion src/exceptions/ModelException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace rjapi\exception;
namespace rjapi\exceptions;

class ModelException extends BaseException
{
Expand Down
2 changes: 1 addition & 1 deletion src/exceptions/SchemaException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace rjapi\exception;
namespace rjapi\exceptions;

class SchemaException extends BaseException
{
Expand Down
9 changes: 6 additions & 3 deletions src/extension/BitMask.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace rjapi\extension;

use rjapi\exception\AttributesException;
use rjapi\exceptions\AttributesException;
use rjapi\types\ConfigInterface;

class BitMask
Expand All @@ -12,10 +12,9 @@ class BitMask

/**
* SpellCheck constructor.
* @param string $entity
* @param array $params
*/
public function __construct(string $entity, array $params)
public function __construct(array $params)
{
$this->entity = $params;
$this->field = key($this->entity);
Expand All @@ -38,6 +37,10 @@ public function getField()
return $this->field;
}

/**
* @return mixed
* @throws AttributesException
*/
public function getFlags()
{
if(empty($this->entity[$this->field][ConfigInterface::FLAGS])) {
Expand Down
2 changes: 1 addition & 1 deletion src/extension/OptionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private function setOptionsOnNotDelete(string $calledMethod) : void
$bitMaskParams = ConfigHelper::getNestedParam(ConfigInterface::BIT_MASK, MigrationsHelper::getTableName($this->entity));
if ($bitMaskParams !== null) {
$this->configOptions->setBitMask(true);
$this->bitMask = new BitMask($this->entity, $bitMaskParams);
$this->bitMask = new BitMask($bitMaskParams);
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/helpers/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
class Console
{
// actions
const CREATED = 'created';
public const CREATED = 'created';

// user colors
const COLOR_RED = 'red';
const COLOR_GREEN = 'green';
const COLOR_YELLOW = 'yellow';
public const COLOR_RED = 'red';
public const COLOR_GREEN = 'green';
public const COLOR_YELLOW = 'yellow';

const ANSI_COLOR_RED = "\x1b[31m";
const ANSI_COLOR_GREEN = "\x1b[32m";
const ANSI_COLOR_YELLOW = "\x1b[33m";
const ANSI_COLOR_RESET = "\x1b[0m";
public const ANSI_COLOR_RED = "\x1b[31m";
public const ANSI_COLOR_GREEN = "\x1b[32m";
public const ANSI_COLOR_YELLOW = "\x1b[33m";
public const ANSI_COLOR_RESET = "\x1b[0m";

private static $colorMaps = [
self::COLOR_RED => self::ANSI_COLOR_RED,
self::COLOR_GREEN => self::ANSI_COLOR_GREEN,
self::COLOR_YELLOW => self::ANSI_COLOR_YELLOW,
];

public static function out(string $str, $color = null)
public static function out(string $str, $color = null) : void
{
echo (($color === null) ? '' : self::$colorMaps[$color]) . $str . (($color === null) ? '' : self::ANSI_COLOR_RESET) . PHP_EOL;
}
Expand Down
66 changes: 66 additions & 0 deletions tests/unit/extension/BitMaskTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace rjapitest\unit\extensions;

use rjapi\extension\BitMask;
use rjapitest\unit\TestCase;

/**
* Class BitMaskTest
* @package rjapitest\unit\extensions
*
* @property BitMask bitMask
*/
class BitMaskTest extends TestCase
{
private const FIELD = 'permissions';
private $bitMask;

public function setUp()
{
parent::setUp();
$this->bitMask = new BitMask([
self::FIELD => [
'enabled' => true,
'flags' => [
'publisher' => 1,
'editor' => 2,
'manager' => 4,
'photo_reporter' => 8,
'admin' => 16,
],
],
]);
}

/**
* @test
* @throws \rjapi\exceptions\AttributesException
* @expectedException \rjapi\exceptions\AttributesException
*/
public function it_gets_flags_and_fields()
{
$this->assertArraySubset([
'publisher' => 1,
'editor' => 2,
'manager' => 4,
'photo_reporter' => 8,
'admin' => 16,
], $this->bitMask->getFlags());
$this->assertTrue($this->bitMask->isEnabled());
$this->assertFalse($this->bitMask->isHidden());
$this->assertEquals(self::FIELD, $this->bitMask->getField());
// testing that it throws exception
$this->bitMask = new BitMask([
self::FIELD => [
'enabled' => true,
'publisher' => 1,
'editor' => 2,
'manager' => 4,
'photo_reporter' => 8,
'admin' => 16,
],
]);
$this->bitMask->getFlags();
}
}

0 comments on commit 0545590

Please sign in to comment.