Skip to content

Commit

Permalink
Merge pull request #72 from younes0/master
Browse files Browse the repository at this point in the history
renamed Type classes for php7 support
  • Loading branch information
raulfraile committed Dec 21, 2015
2 parents 5c27eb1 + c6d86d7 commit c0d6d66
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 68 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm-nightly

matrix:
Expand Down
18 changes: 5 additions & 13 deletions src/Ladybug/Renderer/Twig/Extension/BaseExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public function getName()
public function getFunctions()
{
return array(
'render_type' => new \Twig_Function_Method(
$this,
'renderTypeFunction',
'render_type' => new \Twig_SimpleFunction(
'renderTypeFunction',
array($this, 'renderTypeFunction'),
array('needs_environment' => true, 'is_safe' => array('html'))
)
);
Expand All @@ -56,16 +56,8 @@ public function getFunctions()
public function getFilters()
{
return array(
'repeat' => new \Twig_Filter_Method(
$this,
'getRepeat',
array('is_safe' => array('html'))
),
'pad' => new \Twig_Filter_Method(
$this,
'getPad',
array()
)
'repeat' => new \Twig_SimpleFilter('getRepeat', array($this, 'getRepeat'), array('is_safe' => array('html'))),
'pad' => new \Twig_SimpleFilter('getPad', array($this, 'getPad')),
);
}

Expand Down
6 changes: 1 addition & 5 deletions src/Ladybug/Renderer/Twig/Extension/ConsoleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ public function getName()
public function getFilters()
{
return array_merge(parent::getFilters(), array(
'tags' => new \Twig_Filter_Method(
$this,
'getTags',
array('is_safe' => array('html'))
)
'tags' => new \Twig_SimpleFilter('getTags', array($this, 'getTags'), array('is_safe' => array('html'))),
));
}

Expand Down
12 changes: 6 additions & 6 deletions src/Ladybug/Resources/container/types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@

<services>

<service id="type_null" class="Ladybug\Type\Null">
<service id="type_null" class="Ladybug\Type\NullType">
<tag name="ladybug.type" />
</service>

<service id="type_bool" class="Ladybug\Type\Bool">
<service id="type_bool" class="Ladybug\Type\BoolType">
<tag name="ladybug.type" />
</service>

<service id="type_int" class="Ladybug\Type\Int">
<service id="type_int" class="Ladybug\Type\IntType">
<tag name="ladybug.type" />
</service>

<service id="type_float" class="Ladybug\Type\Float">
<service id="type_float" class="Ladybug\Type\FloatType">
<tag name="ladybug.type" />
</service>

<service id="type_string" class="Ladybug\Type\String">
<service id="type_string" class="Ladybug\Type\StringType">
<tag name="ladybug.type" />
</service>

Expand All @@ -41,7 +41,7 @@
<tag name="ladybug.type" />
</service>

<service id="type_resource" class="Ladybug\Type\Resource">
<service id="type_resource" class="Ladybug\Type\ResourceType">
<argument type="service" id="type_factory"></argument>
<argument type="service" id="inspector_manager"></argument>
<argument type="service" id="metadata_resolver"></argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* Bool is an abstraction of a primitive variable of type 'bool'
*/
class Bool extends AbstractType
class BoolType extends AbstractType
{

const TYPE_ID = 'bool';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* Float is an abstraction of a primitive variable of type 'float'
*/
class Float extends AbstractType
class FloatType extends AbstractType
{

const TYPE_ID = 'float';
Expand Down
2 changes: 1 addition & 1 deletion src/Ladybug/Type/Int.php → src/Ladybug/Type/IntType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* Int is an abstraction of a primitive variable of type 'int'
*/
class Int extends AbstractType
class IntType extends AbstractType
{

const TYPE_ID = 'int';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* Null is an abstraction of a primitive variable of type 'null'
*/
class Null extends AbstractType
class NullType extends AbstractType
{
const TYPE_ID = 'null';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Ladybug\Inspector\InspectorManager;
use Ladybug\Model\VariableWrapper;

class Resource extends AbstractType
class ResourceType extends AbstractType
{

const TYPE_ID = 'resource';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* String is an abstraction of a primitive variable of type 'string'
*/
class String extends AbstractType
class StringType extends AbstractType
{
const TYPE_ID = 'string';

Expand Down
2 changes: 1 addition & 1 deletion tests/Ladybug/Tests/Model/VariableWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class VariableWrapperTest extends \PHPUnit_Framework_TestCase

public function testObjectCreation()
{
$var = new \Ladybug\Type\Int();
$var = new \Ladybug\Type\IntType();
$var->load(1);

$variableWrapper = new VariableWrapper(1, $var, VariableWrapper::TYPE_CLASS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

use Ladybug\Type;

class BoolTest extends \PHPUnit_Framework_TestCase
class BoolTypeTest extends \PHPUnit_Framework_TestCase
{

/** @var Type\Bool $type */
protected $type;

public function setUp()
{
$this->type = new Type\Bool();
$this->type = new Type\BoolType();
}

public function testLoaderForValidValues()
Expand Down
28 changes: 14 additions & 14 deletions tests/Ladybug/Tests/Type/FactoryTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function setUp()
/*$maxlevel = 8;
$factoryTypeMock = m::mock('Ladybug\Type\FactoryType');
$factoryTypeMock->shouldReceive('factory')->with(m::anyOf(1, 2, 3), m::any())->andReturn(new Type\Int());
$factoryTypeMock->shouldReceive('factory')->with(m::anyOf(1, 2, 3), m::any())->andReturn(new Type\IntType());
*/

$managerInspectorMock = m::mock('Ladybug\Inspector\InspectorManager');
Expand All @@ -26,14 +26,14 @@ public function setUp()
$metadataResolverMock->shouldReceive('has')->andReturn(false);

$this->factory = new Type\FactoryType();
$this->factory->add(new Type\Int(), 'type_int');
$this->factory->add(new Type\Bool(), 'type_bool');
$this->factory->add(new Type\Null(), 'type_null');
$this->factory->add(new Type\Float(), 'type_float');
$this->factory->add(new Type\String(), 'type_string');
$this->factory->add(new Type\IntType(), 'type_int');
$this->factory->add(new Type\BoolType(), 'type_bool');
$this->factory->add(new Type\NullType(), 'type_null');
$this->factory->add(new Type\FloatType(), 'type_float');
$this->factory->add(new Type\StringType(), 'type_string');
$this->factory->add(new Type\Vector\Container(8, $this->factory), 'type_array');
$this->factory->add(new Type\Object\Container(8, $this->factory, $managerInspectorMock, $metadataResolverMock), 'type_object');
$this->factory->add(new Type\Resource($this->factory, $managerInspectorMock, $metadataResolverMock), 'type_resource');
$this->factory->add(new Type\ResourceType($this->factory, $managerInspectorMock, $metadataResolverMock), 'type_resource');
}

public function tearDown()
Expand All @@ -45,35 +45,35 @@ public function testFactoryForIntValues()
{
$var = 1;
$type = $this->factory->factory($var);
$this->assertEquals('Ladybug\\Type\\Int', get_class($type));
$this->assertEquals('Ladybug\\Type\\IntType', get_class($type));
}

public function testFactoryForBoolValues()
{
$var = true;
$type = $this->factory->factory($var);
$this->assertEquals('Ladybug\\Type\\Bool', get_class($type));
$this->assertEquals('Ladybug\\Type\\BoolType', get_class($type));
}

public function testFactoryForFloatValues()
{
$var = 1.2;
$type = $this->factory->factory($var);
$this->assertEquals('Ladybug\\Type\\Float', get_class($type));
$this->assertEquals('Ladybug\\Type\\FloatType', get_class($type));
}

public function testFactoryForNullValues()
{
$var = null;
$type = $this->factory->factory($var);
$this->assertEquals('Ladybug\\Type\\Null', get_class($type));
$this->assertEquals('Ladybug\\Type\\NullType', get_class($type));
}

public function testFactoryForStringValues()
{
$var = 'test';
$type = $this->factory->factory($var);
$this->assertEquals('Ladybug\\Type\\String', get_class($type));
$this->assertEquals('Ladybug\\Type\\StringType', get_class($type));
}

public function testFactoryForArrayValues()
Expand All @@ -94,15 +94,15 @@ public function testFactoryForResourceValues()
{
$var = fopen(__DIR__ . '/../../../files/test.txt', 'rb');
$type = $this->factory->factory($var);
$this->assertInstanceOf('Ladybug\\Type\\Resource', $type);
$this->assertInstanceOf('Ladybug\\Type\\ResourceType', $type);
}

public function testFactoryForUnknownResourceValues()
{
$var = fopen(__DIR__ . '/../../../files/test.txt', 'rb');
fclose($var); // Turns resource into type "Unknown"
$type = $this->factory->factory($var);
$this->assertInstanceOf('Ladybug\\Type\\Resource', $type);
$this->assertInstanceOf('Ladybug\\Type\\ResourceType', $type);
}

/*public function testLoaderForOtherType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

use Ladybug\Type;

class FloatTest extends \PHPUnit_Framework_TestCase
class FloatTypeTest extends \PHPUnit_Framework_TestCase
{

/** @var Type\Float $type */
protected $type;

public function setUp()
{
$this->type = new Type\Float();
$this->type = new Type\FloatType();
}

public function testLoaderForValidValues()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

use Ladybug\Type;

class IntTest extends \PHPUnit_Framework_TestCase
class IntTypeTest extends \PHPUnit_Framework_TestCase
{

/** @var Type\Int $type */
protected $type;

public function setUp()
{
$this->type = new Type\Int();
$this->type = new Type\IntType();
}

public function testLoaderForValidValues()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

use Ladybug\Type;

class NullTest extends \PHPUnit_Framework_TestCase
class NullTypeTest extends \PHPUnit_Framework_TestCase
{

/** @var Type\Null $type */
protected $type;

public function setUp()
{
$this->type = new Type\Null();
$this->type = new Type\NullType();
}

public function testLoaderForValidValues()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class BadTypeHintedParameterContainerTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$factory = new Type\FactoryType();
$factory->add(new Type\Null(), 'type_null');
$factory->add(new Type\NullType(), 'type_null');

$managerInspectorMock = m::mock('Ladybug\Inspector\InspectorManager');
$managerInspectorMock->shouldReceive('get')->andReturn(null);
Expand Down Expand Up @@ -53,7 +53,7 @@ public function testDumperDoesNotCrashOnWrongTypeHints()
$badTypeHinted = $privateMethod->getParameterByName('baz');
$this->assertEquals('[Undefined Type Hint]', $badTypeHinted->getType());
$this->assertFalse($badTypeHinted->isReference());
$this->assertInstanceOf('Ladybug\Type\Null', $badTypeHinted->getDefaultValue());
$this->assertInstanceOf('Ladybug\Type\NullType', $badTypeHinted->getDefaultValue());
}
}

Expand Down
12 changes: 6 additions & 6 deletions tests/Ladybug/Tests/Type/Object/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function setUp()
$maxlevel = 8;
$factoryTypeMock = m::mock('Ladybug\Type\FactoryType');
$factoryTypeMock->shouldReceive('factory')->with(m::anyOf(1, 2, 3, 4), m::any())->andReturnUsing(function($var, $level) {
$intType = new Type\Int();
$intType = new Type\IntType();
$intType->load($var, $level);

return $intType;
Expand Down Expand Up @@ -61,29 +61,29 @@ public function testLoaderForValidValues()
$this->assertInstanceOf('Ladybug\Type\Object\Property', $privateProperty);
$this->assertEquals('privateProperty', $privateProperty->getName());
$this->assertEquals(VisibilityInterface::VISIBILITY_PRIVATE, $privateProperty->getVisibility());
$this->assertInstanceOf('Ladybug\Type\Int', $privateProperty->getValue());
$this->assertInstanceOf('Ladybug\Type\IntType', $privateProperty->getValue());
$this->assertEquals(2, $privateProperty->getLevel());
$this->assertEquals('Ladybug\Tests\Type\Object\Bar', $privateProperty->getOwner());

$this->assertInstanceOf('Ladybug\Type\Object\Property', $protectedProperty);
$this->assertEquals('protectedProperty', $protectedProperty->getName());
$this->assertEquals(VisibilityInterface::VISIBILITY_PROTECTED, $protectedProperty->getVisibility());
$this->assertInstanceOf('Ladybug\Type\Int', $protectedProperty->getValue());
$this->assertInstanceOf('Ladybug\Type\IntType', $protectedProperty->getValue());
$this->assertEquals(2, $protectedProperty->getLevel());
$this->assertEquals('Ladybug\Tests\Type\Object\Bar', $protectedProperty->getOwner());

$this->assertInstanceOf('Ladybug\Type\Object\Property', $publicProperty);
$this->assertEquals('publicProperty', $publicProperty->getName());
$this->assertEquals(VisibilityInterface::VISIBILITY_PUBLIC, $publicProperty->getVisibility());
$this->assertInstanceOf('Ladybug\Type\Int', $publicProperty->getValue());
$this->assertInstanceOf('Ladybug\Type\IntType', $publicProperty->getValue());
$this->assertEquals(2, $publicProperty->getLevel());
$this->assertEquals('Ladybug\Tests\Type\Object\Bar', $publicProperty->getOwner());

// constants
$this->assertEquals(1, count($this->type->getClassConstants()));
$constant = $this->type->getConstantByName('CONSTANT');
$this->assertEquals('CONSTANT', $constant->getName());
$this->assertInstanceOf('Ladybug\Type\Int', $constant->getValue());
$this->assertInstanceOf('Ladybug\Type\IntType', $constant->getValue());
$this->assertEquals(2, $constant->getLevel());

// methods
Expand Down Expand Up @@ -138,7 +138,7 @@ public function testLoaderForValidValues()

$this->assertEquals('p5', $parameter5->getName());
$this->assertFalse($parameter5->isReference());
$this->assertInstanceOf('Ladybug\Type\Int', $parameter5->getDefaultValue());
$this->assertInstanceOf('Ladybug\Type\IntType', $parameter5->getDefaultValue());
$this->assertNull($parameter5->getType());

// method info
Expand Down
Loading

0 comments on commit c0d6d66

Please sign in to comment.