Skip to content

Commit

Permalink
test: improve some PHPUnit assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
peter279k authored and ramsey committed Dec 27, 2022
1 parent 49f291f commit 45e3a14
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 82 deletions.
70 changes: 35 additions & 35 deletions tests/CollectionManipulationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public function testSortNameAscWithAscendingIdAndNames(): void
$sortedCollection = $barCollection->sort('name');

$this->assertNotSame($barCollection, $sortedCollection);
$this->assertEquals([$bar1, $bar2, $bar3], $sortedCollection->toArray());
$this->assertSame([$bar1, $bar2, $bar3], $sortedCollection->toArray());
// Make sure original collection is untouched
$this->assertEquals([$bar3, $bar2, $bar1], $barCollection->toArray());
$this->assertSame([$bar3, $bar2, $bar1], $barCollection->toArray());
}

public function testSortNameAscWithDescendingNames(): void
Expand All @@ -48,9 +48,9 @@ public function testSortNameAscWithDescendingNames(): void
$sortedCollection = $barCollection->sort('name');

$this->assertNotSame($barCollection, $sortedCollection);
$this->assertEquals([$bar3, $bar2, $bar1], $sortedCollection->toArray());
$this->assertSame([$bar3, $bar2, $bar1], $sortedCollection->toArray());
// Make sure original collection is untouched
$this->assertEquals([$bar1, $bar2, $bar3], $barCollection->toArray());
$this->assertSame([$bar1, $bar2, $bar3], $barCollection->toArray());
}

public function testSortNameDescWithDescendingNames(): void
Expand All @@ -63,9 +63,9 @@ public function testSortNameDescWithDescendingNames(): void
$sortedCollection = $barCollection->sort('name', 'desc');

$this->assertNotSame($barCollection, $sortedCollection);
$this->assertEquals([$bar1, $bar2, $bar3], $sortedCollection->toArray());
$this->assertSame([$bar1, $bar2, $bar3], $sortedCollection->toArray());
// Make sure original collection is untouched
$this->assertEquals([$bar1, $bar2, $bar3], $barCollection->toArray());
$this->assertSame([$bar1, $bar2, $bar3], $barCollection->toArray());
}

public function testSortNameDescWithMethod(): void
Expand All @@ -78,9 +78,9 @@ public function testSortNameDescWithMethod(): void
$sortedCollection = $barCollection->sort('getName', 'desc');

$this->assertNotSame($barCollection, $sortedCollection);
$this->assertEquals([$bar1, $bar2, $bar3], $sortedCollection->toArray());
$this->assertSame([$bar1, $bar2, $bar3], $sortedCollection->toArray());
// Make sure original collection is untouched
$this->assertEquals([$bar1, $bar2, $bar3], $barCollection->toArray());
$this->assertSame([$bar1, $bar2, $bar3], $barCollection->toArray());
}

public function testSortNameWithInvalidProperty(): void
Expand Down Expand Up @@ -114,10 +114,10 @@ public function testFilter(): void
$filteredCollection = $barCollection->filter(fn ($item) => $item->name === 'a');

$this->assertNotSame($barCollection, $filteredCollection);
$this->assertEquals([$bar1], $filteredCollection->toArray());
$this->assertSame([$bar1], $filteredCollection->toArray());

// Make sure original collection is untouched
$this->assertEquals([$bar1, $bar2], $barCollection->toArray());
$this->assertSame([$bar1, $bar2], $barCollection->toArray());
}

public function testWhereWithTypeSafePropertyValue(): void
Expand All @@ -129,9 +129,9 @@ public function testWhereWithTypeSafePropertyValue(): void
$whereCollection = $barCollection->where('name', 'b');

$this->assertNotSame($barCollection, $whereCollection);
$this->assertEquals([$bar2], $whereCollection->toArray());
$this->assertSame([$bar2], $whereCollection->toArray());
// Make sure original collection is untouched
$this->assertEquals([$bar1, $bar2], $barCollection->toArray());
$this->assertSame([$bar1, $bar2], $barCollection->toArray());
}

public function testWhereWithTypeUnsafePropertyValue(): void
Expand All @@ -143,9 +143,9 @@ public function testWhereWithTypeUnsafePropertyValue(): void
$whereCollection = $barCollection->where('id', '1');

$this->assertNotSame($barCollection, $whereCollection);
$this->assertEquals([], $whereCollection->toArray());
$this->assertSame([], $whereCollection->toArray());
// Make sure original collection is untouched
$this->assertEquals([$bar1, $bar2], $barCollection->toArray());
$this->assertSame([$bar1, $bar2], $barCollection->toArray());
}

public function testWhereWithTypeSafeMethodValue(): void
Expand All @@ -157,9 +157,9 @@ public function testWhereWithTypeSafeMethodValue(): void
$whereCollection = $barCollection->where('getName', 'b');

$this->assertNotSame($barCollection, $whereCollection);
$this->assertEquals([$bar2], $whereCollection->toArray());
$this->assertSame([$bar2], $whereCollection->toArray());
// Make sure original collection is untouched
$this->assertEquals([$bar1, $bar2], $barCollection->toArray());
$this->assertSame([$bar1, $bar2], $barCollection->toArray());
}

public function testMapShouldRunOverEachItem(): void
Expand Down Expand Up @@ -236,17 +236,17 @@ public function testDiff(): void
$this->assertNotSame($diffCollection1, $barCollection1);
$this->assertNotSame($diffCollection1, $barCollection2);
$this->assertNotSame($diffCollection1, $barCollection3);
$this->assertEquals([$bar2], $diffCollection1->toArray());
$this->assertSame([$bar2], $diffCollection1->toArray());

$this->assertNotSame($diffCollection2, $barCollection1);
$this->assertNotSame($diffCollection2, $barCollection2);
$this->assertNotSame($diffCollection2, $barCollection3);
$this->assertEquals([$bar2], $diffCollection2->toArray());
$this->assertSame([$bar2], $diffCollection2->toArray());

// Make sure original collections are untouched
$this->assertEquals([$bar1], $barCollection1->toArray());
$this->assertEquals([$bar1, $bar2], $barCollection2->toArray());
$this->assertEquals([$bar2, $bar1], $barCollection3->toArray());
$this->assertSame([$bar1], $barCollection1->toArray());
$this->assertSame([$bar1, $bar2], $barCollection2->toArray());
$this->assertSame([$bar2, $bar1], $barCollection3->toArray());
}

public function testdiffShouldRaiseExceptionOnDiverseCollectionType(): void
Expand All @@ -272,7 +272,7 @@ public function testDiffGenericCollection(): void

$diffCollection = $barCollection1->diff($barCollection2);

$this->assertEquals([$bar2], $diffCollection->toArray());
$this->assertSame([$bar2], $diffCollection->toArray());
}

public function testIntersectShouldRaiseExceptionOnDiverseCollections(): void
Expand Down Expand Up @@ -302,17 +302,17 @@ public function testIntersect(): void
$this->assertNotSame($intersectCollection1, $barCollection1);
$this->assertNotSame($intersectCollection1, $barCollection2);
$this->assertNotSame($intersectCollection1, $barCollection3);
$this->assertEquals([$bar1, $bar2], $intersectCollection1->toArray());
$this->assertSame([$bar1, $bar2], $intersectCollection1->toArray());

$this->assertNotSame($intersectCollection2, $barCollection1);
$this->assertNotSame($intersectCollection2, $barCollection2);
$this->assertNotSame($intersectCollection2, $barCollection3);
$this->assertEquals([$bar1, $bar2], $intersectCollection2->toArray());
$this->assertSame([$bar1, $bar2], $intersectCollection2->toArray());

// Make sure original collections are untouched
$this->assertEquals([$bar1, $bar2], $barCollection1->toArray());
$this->assertEquals([$bar1, $bar2, $bar3], $barCollection2->toArray());
$this->assertEquals([$bar3, $bar2, $bar1], $barCollection3->toArray());
$this->assertSame([$bar1, $bar2], $barCollection1->toArray());
$this->assertSame([$bar1, $bar2, $bar3], $barCollection2->toArray());
$this->assertSame([$bar3, $bar2, $bar1], $barCollection3->toArray());
}

public function testIntersectShouldRaiseExceptionOnDiverseCollectionType(): void
Expand All @@ -338,7 +338,7 @@ public function testIntersectGenericCollection(): void

$diffCollection = $barCollection1->intersect($barCollection2);

$this->assertEquals([$bar1], $diffCollection->toArray());
$this->assertSame([$bar1], $diffCollection->toArray());
}

public function testMergeShouldRaiseExceptionOnDiverseCollection(): void
Expand Down Expand Up @@ -366,12 +366,12 @@ public function testMerge(): void

$mergeCollection = $barCollection1->merge($barCollection2, $barCollection3);
$this->assertNotSame($mergeCollection, $barCollection1);
$this->assertEquals([$bar1, $bar2, $bar3], $mergeCollection->toArray());
$this->assertSame([$bar1, $bar2, $bar3], $mergeCollection->toArray());

// Make sure the original collections are untouched
$this->assertEquals([$bar1], $barCollection1->toArray());
$this->assertEquals([$bar2], $barCollection2->toArray());
$this->assertEquals([$bar3], $barCollection3->toArray());
$this->assertSame([$bar1], $barCollection1->toArray());
$this->assertSame([$bar2], $barCollection2->toArray());
$this->assertSame([$bar3], $barCollection3->toArray());
}

public function testMergeWhenTheSameObjectAppearsInMultipleCollections(): void
Expand All @@ -385,7 +385,7 @@ public function testMergeWhenTheSameObjectAppearsInMultipleCollections(): void
$barCollection3 = new BarCollection([$bar3, $bar2]);

$mergeCollection = $barCollection1->merge($barCollection2, $barCollection3);
$this->assertEquals([$bar1, $bar2, $bar1, $bar3, $bar2], $mergeCollection->toArray());
$this->assertSame([$bar1, $bar2, $bar1, $bar3, $bar2], $mergeCollection->toArray());
}

public function testMergeFunctionalityWithKeys(): void
Expand All @@ -399,7 +399,7 @@ public function testMergeFunctionalityWithKeys(): void
$barCollection3 = new BarCollection(['c' => $bar3, 'd' => $bar2]);

$mergeCollection = $barCollection1->merge($barCollection2, $barCollection3);
$this->assertEquals(['a' => $bar1, 'b' => $bar2, 'c' => $bar3, 'd' => $bar2], $mergeCollection->toArray());
$this->assertSame(['a' => $bar1, 'b' => $bar2, 'c' => $bar3, 'd' => $bar2], $mergeCollection->toArray());
}

public function testMergeShouldRaiseExceptionOnDiverseCollectionType(): void
Expand All @@ -425,7 +425,7 @@ public function testMergeGenericCollection(): void

$diffCollection = $barCollection1->merge($barCollection2);

$this->assertEquals([$bar1, $bar2], $diffCollection->toArray());
$this->assertSame([$bar1, $bar2], $diffCollection->toArray());
}

public function testMapConvertsValues(): void
Expand Down
10 changes: 5 additions & 5 deletions tests/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testConstructorSetsType(): void
{
$collection = new Collection('string');

$this->assertEquals('string', $collection->getType());
$this->assertSame('string', $collection->getType());
}

public function testConstructorWithData(): void
Expand Down Expand Up @@ -183,7 +183,7 @@ public function testColumnByProperty(): void
$bar3 = new Bar(3, 'c');
$barCollection = new BarCollection([$bar1, $bar2, $bar3]);

$this->assertEquals(['a', 'b', 'c'], $barCollection->column('name'));
$this->assertSame(['a', 'b', 'c'], $barCollection->column('name'));
}

public function testColumnByMethod(): void
Expand All @@ -193,7 +193,7 @@ public function testColumnByMethod(): void
$bar3 = new Bar(3, 'c');
$barCollection = new BarCollection([$bar1, $bar2, $bar3]);

$this->assertEquals([1, 2, 3], $barCollection->column('getId'));
$this->assertSame([1, 2, 3], $barCollection->column('getId'));
}

public function testColumnShouldRaiseExceptionOnUndefinedPropertyOrMethod(): void
Expand Down Expand Up @@ -224,7 +224,7 @@ public function testFirst(): void

$this->assertSame($bar1, $barCollection->first());
// Make sure the collection stays unchanged
$this->assertEquals([$bar1, $bar2, $bar3], $barCollection->toArray());
$this->assertSame([$bar1, $bar2, $bar3], $barCollection->toArray());
}

public function testLastShouldRaiseExceptionOnEmptyCollection(): void
Expand All @@ -245,7 +245,7 @@ public function testLast(): void

$this->assertSame($bar3, $barCollection->last());
// Make sure the collection stays unchanged
$this->assertEquals([$bar1, $bar2, $bar3], $barCollection->toArray());
$this->assertSame([$bar1, $bar2, $bar3], $barCollection->toArray());
}

public function testSerializable(): void
Expand Down
4 changes: 2 additions & 2 deletions tests/DoubleEndedQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testConstructorSetsType(): void
/** @var DoubleEndedQueue<int> $queue */
$queue = new DoubleEndedQueue('integer');

$this->assertEquals('integer', $queue->getType());
$this->assertSame('integer', $queue->getType());
}

public function testConstructorWithData(): void
Expand Down Expand Up @@ -119,7 +119,7 @@ public function testIterateOverQueue(): void

$id = 0;
foreach ($queue as $item) {
$this->assertEquals($id, $item->id);
$this->assertSame($id, $item->id);
$id++;
}
}
Expand Down
10 changes: 5 additions & 5 deletions tests/GenericArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testConstructWithArray(): void
$phpArray = ['foo' => 'bar', 'baz'];
$genericArrayObject = new GenericArray($phpArray);

$this->assertEquals($phpArray, $genericArrayObject->toArray());
$this->assertSame($phpArray, $genericArrayObject->toArray());
$this->assertFalse($genericArrayObject->isEmpty());
}

Expand All @@ -49,12 +49,12 @@ public function testArrayAccess(): void

$this->assertTrue(isset($genericArrayObject['foo']));
$this->assertFalse(isset($genericArrayObject['bar']));
$this->assertEquals($phpArray['foo'], $genericArrayObject['foo']);
$this->assertSame($phpArray['foo'], $genericArrayObject['foo']);

$genericArrayObject['bar'] = 456;
unset($genericArrayObject['foo']);

$this->assertEquals(456, $genericArrayObject['bar']);
$this->assertSame(456, $genericArrayObject['bar']);
$this->assertArrayNotHasKey('key', $genericArrayObject);
}

Expand All @@ -63,7 +63,7 @@ public function testOffsetSetWithEmptyOffset(): void
$genericArrayObject = new GenericArray();
$genericArrayObject[] = 123;

$this->assertEquals(123, $genericArrayObject[0]);
$this->assertSame(123, $genericArrayObject[0]);
}

/**
Expand Down Expand Up @@ -104,7 +104,7 @@ public function testClear(): void
$phpArray = ['foo' => 'bar'];
$genericArrayObject = new GenericArray($phpArray);

$this->assertEquals($phpArray, $genericArrayObject->toArray());
$this->assertSame($phpArray, $genericArrayObject->toArray());

$genericArrayObject->clear();

Expand Down
Loading

0 comments on commit 45e3a14

Please sign in to comment.