Skip to content

Commit

Permalink
Defined properties interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Magomogo committed Sep 27, 2013
1 parent 7e70c12 commit dc93b81
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 28 deletions.
6 changes: 0 additions & 6 deletions lib/Magomogo/Persisted/AbstractProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ public function id($container)
$this->idInContainer[get_class($container)] : null;
}

public function resetPersistency()
{
$this->idInContainer = array();
return $this;
}

public function naturalKey()
{
return null;
Expand Down
64 changes: 64 additions & 0 deletions lib/Magomogo/Persisted/PropertiesInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
namespace Magomogo\Persisted;

use Magomogo\Persisted\Container\ContainerInterface;

interface PropertiesInterface
{
/**
* Returns unique identifier in given container
*
* @param ContainerInterface $container
* @return mixed
*/
public function id($container);

/**
* Optionally defines natural key value
* null value forces container to set its artificial identifier
*
* @return mixed
*/
public function naturalKey();

/**
* The message. A container stored properties giving particular identifier
*
* @param mixed $id
* @param ContainerInterface $container
*/
public function persisted($id, $container);

/**
* Load all values from the container
*
* @param ContainerInterface$container
* @param mixed $id
* @return $this
*/
public function loadFrom($container, $id);

/**
* Save all value to the container
*
* @param ContainerInterface $container
* @return string unique identifier
*/
public function putIn($container);

/**
* Delete this properties form the container
*
* @param ContainerInterface $container
* @return void
*/
public function deleteFrom($container);

/**
* Copy state to another properties of same type
*
* @param self $properties
* @return self
*/
public function copyTo($properties);
}
8 changes: 0 additions & 8 deletions test/Persisted/AbstractPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,6 @@ public function testIssetMagicMethod()
$this->assertFalse(isset(self::properties()->not_existing));
}

public function testPersistencyCanBeReset()
{
$bag = self::properties();
$bag->persisted(88, new \stdClass());
$this->assertEquals(88, $bag->id(new \stdClass()));
$this->assertNull($bag->resetPersistency()->id(new \stdClass()));
}

//----------------------------------------------------------------------------------------------------------------------

private static function properties()
Expand Down
15 changes: 1 addition & 14 deletions test/Persisted/Container/MemoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function testCanSaveAndLoadAJobRecord()
$jobRecord = new JobRecord\Model(ObjectMother\Company::xiag(), ObjectMother\Company::nstu());
$id = $jobRecord->save($container);

$this->assertModelsAreEqual(
$this->assertEquals(
$jobRecord,
JobRecord\Model::load($container, $id)
);
Expand All @@ -128,17 +128,4 @@ public function testProvidesCorrectInstanceOfAggregatedProperties()
$personProperties->creditCard->paymentSystem()
);
}

/**
* @param ModelInterface $model1
* @param ModelInterface $model2
*/
private function assertModelsAreEqual($model1, $model2)
{
$container = new Memory();
$this->assertEquals(
$container->exposeProperties($model1)->resetPersistency(),
$container->exposeProperties($model2)->resetPersistency()
);
}
}

0 comments on commit dc93b81

Please sign in to comment.