Skip to content

Commit

Permalink
Add a bunch of tests on Set::changes property
Browse files Browse the repository at this point in the history
  • Loading branch information
Taluu committed Jun 1, 2014
1 parent ed7eb23 commit c4a9f09
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/AbstractSnapshot.php
Expand Up @@ -11,9 +11,10 @@

namespace Totem;

use ArrayAccess;
use ArrayAccess,
ReflectionClass,

use BadMethodCallException,
BadMethodCallException,
InvalidArgumentException;

use Totem\Exception\IncomparableDataException;
Expand Down
1 change: 1 addition & 0 deletions src/Set.php
Expand Up @@ -17,6 +17,7 @@
ArrayIterator,
IteratorAggregate,

RuntimeException,
OutOfBoundsException,
BadMethodCallException;

Expand Down
16 changes: 16 additions & 0 deletions test/AbstractSnapshotTest.php
Expand Up @@ -91,5 +91,21 @@ public function testDiff()

$this->assertInstanceOf('Totem\\Set', $snapshot->diff($snapshot));
}

public function testCorrectSetClass()
{
$snapshot = new Snapshot(['data' => []]);
$snapshot->setSetClass('Totem\\Set');
}

/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage A Set Class should be instantiable and implement Totem\SetInterface
*/
public function testWrongSetClass()
{
$snapshot = new Snapshot(['data' => []]);
$snapshot->setSetClass('stdclass');
}
}

45 changes: 45 additions & 0 deletions test/SetTest.php
Expand Up @@ -136,5 +136,50 @@ public function testForbidenUnsetter()

unset($set[0]);
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage The changeset was not computed yet !
*/
public function testHasChangedNotComputedShouldThrowException()
{
$set = new Set;
$set->hasChanged('foo');
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage The changeset was not computed yet !
*/
public function testNotComputedCountShouldThrowException()
{
$set = new Set;
count($set);
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage The changeset was not computed yet !
*/
public function testNotComputedIteratorShouldThrowException()
{
$set = new Set;
$set->getIterator();
}

public function testAlreadyComputedSetShouldNotRecompute()
{
$old = new Snapshot(['data' => ['foo']]);
$new = new Snapshot(['data' => ['bar']]);

$set = new Set($old, $new); // implicitly compute the set in the constructor

$this->assertCount(1, $set);
$this->assertTrue($set->hasChanged(0));
$this->assertEquals('foo', $set->getChange(0)->getOld());
$this->assertEquals('bar', $set->getChange(0)->getNew());

$set->compute($old, $new);
}
}

0 comments on commit c4a9f09

Please sign in to comment.