mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-06 15:06:31 +02:00
Add unit tests and usage example to README
This commit is contained in:
59
More/EAV/Tests/ValueTest.php
Normal file
59
More/EAV/Tests/ValueTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user