Skip to content

Commit

Permalink
Fix unit tests for StorablePropertyTrait
Browse files Browse the repository at this point in the history
Amends: 83c954e
  • Loading branch information
mcaskill committed Oct 31, 2019
1 parent 5515529 commit 40b3cc8
Showing 1 changed file with 29 additions and 78 deletions.
107 changes: 29 additions & 78 deletions tests/Charcoal/Property/StorablePropertyTraitTest.php
Expand Up @@ -5,7 +5,9 @@
use ReflectionMethod;

// From 'charcoal-property'
use Charcoal\Property\GenericProperty;
use Charcoal\Property\PropertyField;
use Charcoal\Property\StorablePropertyInterface;
use Charcoal\Property\StorablePropertyTrait;
use Charcoal\Tests\AbstractTestCase;
use Charcoal\Tests\ReflectionsTrait;
Expand All @@ -20,7 +22,7 @@ class StorablePropertyTraitTest extends AbstractTestCase
use ContainerIntegrationTrait;

/**
* @var StorablePropertyTrait
* @var StorablePropertyInterfaceß
*/
private $obj;

Expand All @@ -37,98 +39,38 @@ public function setUp()
}

/**
* @return StorablePropertyTrait
* @return GenericProperty
*/
public function createProperty()
{
$container = $this->getContainer();

$obj = $this->getMockForTrait(StorablePropertyTrait::class);

$obj->expects($this->any())
->method('ident')
->will($this->returnValue('test'));

$obj->expects($this->any())
->method('translator')
->will($this->returnValue($container['translator']));

$obj->expects($this->any())
->method('l10n')
->will($this->returnValue(false));
$prop = $container['property/factory']->create(GenericProperty::class);

$obj->expects($this->any())
->method('multiple')
->will($this->returnValue(false));

return $obj;
$prop['ident'] = 'test';
return $prop;
}

/**
* @return StorablePropertyTrait
*/
public function createMultilingualProperty()
{
$container = $this->getContainer();

$obj = $this->getMockForTrait(StorablePropertyTrait::class);
$prop = $this->createProperty();

$obj->expects($this->any())
->method('ident')
->will($this->returnValue('test'));

$obj->expects($this->any())
->method('translator')
->will($this->returnValue($container['translator']));

$obj->expects($this->any())
->method('l10nIdent')
->with($this->isType('string'))
->will($this->returnCallback(function($lang) {
return sprintf('test_%s', $lang);
}));

$obj->expects($this->any())
->method('l10n')
->will($this->returnValue(true));

$obj->expects($this->any())
->method('multiple')
->will($this->returnValue(false));

return $obj;
$prop['l10n'] = true;
return $prop;
}

/**
* @return StorablePropertyTrait
*/
public function createMultiValueProperty()
{
$container = $this->getContainer();
$prop = $this->createProperty();

$obj = $this->getMockForTrait(StorablePropertyTrait::class);

$obj->expects($this->any())
->method('ident')
->will($this->returnValue('test'));

$obj->expects($this->any())
->method('translator')
->will($this->returnValue($container['translator']));

$obj->expects($this->any())
->method('l10n')
->will($this->returnValue(false));

$obj->expects($this->any())
->method('multiple')
->will($this->returnValue(true));

$obj->expects($this->any())
->method('multipleSeparator')
->will($this->returnValue(','));

return $obj;
$prop['multiple'] = true;
return $prop;
}

/**
Expand Down Expand Up @@ -164,20 +106,24 @@ public function testFields()

$this->assertInternalType('array', $fields);
$this->assertCount(1, $fields);
$this->assertInstanceOf(PropertyField::class, $fields[0]);
$this->assertEquals('test', $fields[0]->ident());
$this->assertEquals('Cooking', $fields[0]->val());

$field = reset($fields);

$this->assertInstanceOf(PropertyField::class, $field);
$this->assertEquals('test', $field->ident());
$this->assertEquals('Cooking', $field->val());

$fields = $this->obj->fields([]);
$this->assertEquals('[]', $fields[0]->val());
$field = reset($fields);
$this->assertEquals('[]', $field->val());
}

/**
* @return void
*/
public function testUpdateFields()
{
$this->callMethod($this->obj, 'updatedFields', [ 'Cooking' ]);
$this->callMethod($this->obj, 'updatedFields', [ [], 'Cooking' ]);
}

/**
Expand All @@ -187,6 +133,8 @@ public function testUpdateFields()
*/
public function testMultilingualFields()
{
$container = $this->getContainer();

$obj = $this->createMultilingualProperty();

$fields = $obj->fields('Cooking');
Expand Down Expand Up @@ -223,8 +171,11 @@ public function testFieldNames()

$this->assertInternalType('array', $names);
$this->assertCount(1, $names);
$this->assertInternalType('string', $names[0]);
$this->assertEquals('test', $names[0]);

$name = reset($names);

$this->assertInternalType('string', $name);
$this->assertEquals('test', $name);
}

/**
Expand Down

0 comments on commit 40b3cc8

Please sign in to comment.