Skip to content

Commit

Permalink
Merge pull request #28 from localheinz/fix/assert
Browse files Browse the repository at this point in the history
Fix: Assert sameness, not just equality
  • Loading branch information
nicmart committed Aug 20, 2015
2 parents 6da7794 + b2b243a commit 63ec849
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
32 changes: 16 additions & 16 deletions tests/Builder/NodeBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ public function testConstructor()
{
$builder = new NodeBuilder($node = new Node('node'));

$this->assertEquals($node, $builder->getNode());
$this->assertSame($node, $builder->getNode());
}

public function testSetNodeAndGetNode()
{
$this->builder->setNode($node1 = new Node('node1'));
$this->assertEquals($node1, $this->builder->getNode());
$this->assertSame($node1, $this->builder->getNode());

$this->builder->setNode($node2 = new Node('node2'));
$this->assertEquals($node2, $this->builder->getNode());
$this->assertSame($node2, $this->builder->getNode());
}

public function testLeaf()
Expand All @@ -54,8 +54,8 @@ public function testLeaf()

$children = $this->builder->getNode()->getChildren();

$this->assertEquals('a', $children[0]->getValue());
$this->assertEquals('b', $children[1]->getValue());
$this->assertSame('a', $children[0]->getValue());
$this->assertSame('b', $children[1]->getValue());
}

public function testLeafs()
Expand All @@ -64,8 +64,8 @@ public function testLeafs()

$children = $this->builder->getNode()->getChildren();

$this->assertEquals('a', $children[0]->getValue());
$this->assertEquals('b', $children[1]->getValue());
$this->assertSame('a', $children[0]->getValue());
$this->assertSame('b', $children[1]->getValue());
}

public function testTreeAddNewNodeAsChildOfTheParentNode()
Expand All @@ -79,17 +79,17 @@ public function testTreeAddNewNodeAsChildOfTheParentNode()
;

$node = $this->builder->getNode();
$this->assertEquals(array('a'), $this->childrenValues($node->getChildren()));
$this->assertSame(array('a'), $this->childrenValues($node->getChildren()));

$subtree = $node->getChildren()[0];
$this->assertEquals(array('b', 'c'), $this->childrenValues($subtree->getChildren()));
$this->assertSame(array('b', 'c'), $this->childrenValues($subtree->getChildren()));
}

public function testTree()
{
$this->builder->tree('a')->tree('b');

$this->assertEquals('b', $this->builder->getNode()->getValue());
$this->assertSame('b', $this->builder->getNode()->getValue());
}

public function testEnd()
Expand All @@ -101,27 +101,27 @@ public function testEnd()
->tree('c')
->end();

$this->assertEquals('b', $this->builder->getNode()->getValue());
$this->assertSame('b', $this->builder->getNode()->getValue());

$this->builder->end();
$this->assertEquals('a', $this->builder->getNode()->getValue());
$this->assertSame('a', $this->builder->getNode()->getValue());

$this->builder->end();
$this->assertEquals('root', $this->builder->getNode()->getValue());
$this->assertSame('root', $this->builder->getNode()->getValue());
}

public function testValue()
{
$this->builder->value('foo')->value('bar');

$this->assertEquals('bar', $this->builder->getNode()->getValue());
$this->assertSame('bar', $this->builder->getNode()->getValue());
}

public function testNodeInstanceByValue()
{
$node = $this->builder->nodeInstanceByValue('baz');

$this->assertEquals('baz', $node->getValue());
$this->assertSame('baz', $node->getValue());
$this->assertInstanceOf('Tree\Node\Node', $node);
}

Expand All @@ -135,4 +135,4 @@ private function childrenValues(array $children)
return $node->getValue();
}, $children);
}
}
}
50 changes: 25 additions & 25 deletions tests/Node/NodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public function testSetValue()

$node->setValue('string value');

$this->assertEquals('string value', $node->getValue());
$this->assertSame('string value', $node->getValue());

$node->setValue($object = new \stdClass());
$object->foo = 'bar';

$this->assertEquals($object, $node->getValue());
$this->assertSame($object, $node->getValue());
}

public function testAddAndGetChildren()
Expand All @@ -39,7 +39,7 @@ public function testAddAndGetChildren()
->addChild($child3 = new Node('child3'))
;

$this->assertEquals([$child1, $child2, $child3], $root->getChildren());
$this->assertSame([$child1, $child2, $child3], $root->getChildren());
}

public function testAddChildSetParent()
Expand All @@ -50,8 +50,8 @@ public function testAddChildSetParent()
->addChild($child2 = new Node('child2'))
;

$this->assertEquals($root, $child1->getParent());
$this->assertEquals($root, $child2->getParent());
$this->assertSame($root, $child1->getParent());
$this->assertSame($root, $child2->getParent());
}

public function testSetAndGetParent()
Expand All @@ -61,7 +61,7 @@ public function testSetAndGetParent()

$child->setParent($root);

$this->assertEquals($root, $child->getParent());
$this->assertSame($root, $child->getParent());
}

public function testSetChildren()
Expand All @@ -72,7 +72,7 @@ public function testSetChildren()

$root->setChildren($children);

$this->assertEquals($children, $root->getChildren());
$this->assertSame($children, $root->getChildren());
}

public function testSetChildrenSetParentsReferences()
Expand All @@ -83,8 +83,8 @@ public function testSetChildrenSetParentsReferences()
->addChild($child2 = new Node('child2'))
;

$this->assertEquals($root, $child1->getParent());
$this->assertEquals($root, $child2->getParent());
$this->assertSame($root, $child1->getParent());
$this->assertSame($root, $child2->getParent());
}

public function testRemoveChild()
Expand All @@ -97,7 +97,7 @@ public function testRemoveChild()
->removeChild($child2)
;

$this->assertEquals([$child1, $child3], $root->getChildren());
$this->assertSame([$child1, $child3], $root->getChildren());
}

public function testRemoveChildRemoveParentReference()
Expand Down Expand Up @@ -142,7 +142,7 @@ public function testGetAncestors()
$a->addChild($b = new Node('b'));
$b->addChild($c = new Node('c'));

$this->assertEquals([$root, $a, $b], $c->getAncestors());
$this->assertSame([$root, $a, $b], $c->getAncestors());
}

public function testGetAncestorsAndSelf()
Expand All @@ -151,7 +151,7 @@ public function testGetAncestorsAndSelf()
$root->addChild($a = new Node('a'));
$a->addChild($b = new Node('b'));

$this->assertEquals([$root, $a, $b], $b->getAncestorsAndSelf());
$this->assertSame([$root, $a, $b], $b->getAncestorsAndSelf());
}

public function testGetNeighbors()
Expand All @@ -162,7 +162,7 @@ public function testGetNeighbors()
->addChild($b = new Node('b'))
->addChild($c = new Node('c'));

$this->assertEquals([$b, $c], $a->getNeighbors());
$this->assertSame([$b, $c], $a->getNeighbors());
}

public function testGetNeighborsAndSelf()
Expand All @@ -173,7 +173,7 @@ public function testGetNeighborsAndSelf()
->addChild($b = new Node('b'))
->addChild($c = new Node('c'));

$this->assertEquals([$a, $b, $c], $a->getNeighborsAndSelf());
$this->assertSame([$a, $b, $c], $a->getNeighborsAndSelf());
}

public function testIsLeaf()
Expand Down Expand Up @@ -229,9 +229,9 @@ public function testGetDepth()
->addChild(new Node("b"))
;

$this->assertEquals(1, $child1->getDepth());
$this->assertEquals(0, $root->getDepth());
$this->assertEquals(2, $child4->getDepth());
$this->assertSame(1, $child1->getDepth());
$this->assertSame(0, $root->getDepth());
$this->assertSame(2, $child4->getDepth());
}

public function testGetHeight()
Expand All @@ -248,9 +248,9 @@ public function testGetHeight()
->addChild(new Node("b"))
;

$this->assertEquals(0, $child1->getHeight());
$this->assertEquals(2, $root->getHeight());
$this->assertEquals(1, $child3->getHeight());
$this->assertSame(0, $child1->getHeight());
$this->assertSame(2, $root->getHeight());
$this->assertSame(1, $child3->getHeight());
}


Expand All @@ -274,10 +274,10 @@ public function testGetSize()
->addChild(new Node("f"))
;

$this->assertEquals(9, $root->getSize());
$this->assertEquals(3, $child5->getSize());
$this->assertEquals(4, $child4->getSize());
$this->assertEquals(6, $child3->getSize());
$this->assertEquals(1, $child2->getSize());
$this->assertSame(9, $root->getSize());
$this->assertSame(3, $child5->getSize());
$this->assertSame(4, $child4->getSize());
$this->assertSame(6, $child3->getSize());
$this->assertSame(1, $child2->getSize());
}
}
6 changes: 3 additions & 3 deletions tests/Visitor/YieldVisitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public function testGetYield()

$yield = $root->accept($visitor);

$this->assertEquals([$c, $e, $b], $yield);
$this->assertSame([$c, $e, $b], $yield);
}

public function testTheYieldOfALeafNodeIsTheNodeItself()
{
$node = new Node('node');
$visitor = new YieldVisitor;

$this->assertEquals([$node], $node->accept($visitor));
$this->assertSame([$node], $node->accept($visitor));
}
}
}

0 comments on commit 63ec849

Please sign in to comment.