mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-28 10:40:17 +02:00
60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace DesignPatterns\More\EAV\Tests;
|
|
|
|
use DesignPatterns\More\EAV\Attribute;
|
|
use DesignPatterns\More\EAV\Value;
|
|
|
|
/**
|
|
* ValueTest tests the Value model of EAV pattern
|
|
*/
|
|
class ValueTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function testCreationFailureWithoutAttribute()
|
|
{
|
|
$isFailure = false;
|
|
|
|
try {
|
|
new Value();
|
|
} catch (\Exception $e) {
|
|
$isFailure = true;
|
|
}
|
|
|
|
$this->assertTrue($isFailure);
|
|
}
|
|
|
|
public function testCreationSuccessWithAttribute()
|
|
{
|
|
$attribute = new Attribute();
|
|
$attribute->setName('Color');
|
|
|
|
$value = new Value($attribute);
|
|
|
|
$this->assertInstanceOf('\DesignPatterns\More\EAV\Value', $value);
|
|
}
|
|
|
|
public function testSetGetName()
|
|
{
|
|
$attribute = new Attribute();
|
|
$attribute->setName('Color');
|
|
|
|
$value = new Value($attribute);
|
|
$value->setName('Silver');
|
|
|
|
$this->assertEquals('Silver', $value->getName());
|
|
}
|
|
|
|
public function testSetGetAttribute()
|
|
{
|
|
$attribute = new Attribute();
|
|
$attribute->setName('Color');
|
|
|
|
$value = new Value($attribute);
|
|
$value->setName('Silver');
|
|
$this->assertSame($attribute, $value->getAttribute());
|
|
|
|
$value->setAttribute($attribute);
|
|
$this->assertSame($attribute, $value->getAttribute());
|
|
}
|
|
}
|