diff --git a/.gitignore b/.gitignore index 6531974..3fd5f04 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,3 @@ coveralls-upload.json vendor composer.lock bin - diff --git a/.travis.yml b/.travis.yml index 13a0d20..fdbb482 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,9 @@ language: php php: - - 5.4 - - 5.5 - - 5.6 - - 7.0 - - hhvm + - 7.3 + - 7.4 + - 8.0 sudo: false diff --git a/README.md b/README.md index 7a0e577..c4662f8 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Totem \\\\//// |.)(.| | || | Changeset calculator between two state of a data - \(__)/ Requires PHP 5.4 ; Compatible PHP 5.5, PHP 5.6, PHP 7 and HHVM + \(__)/ Compatibile with PHP 7.3, 7.4 or 8.0 |-..-| |o\/o| .----\ /----. diff --git a/composer.json b/composer.json index 36e1802..a72facf 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ }, "require": { - "php": "^5.4 || ^7.0", + "php": "^7.3 || ^8.0", "symfony/property-access": "^2.5 || ^3.0" }, @@ -40,5 +40,9 @@ "branch-alias": { "dev-master": "1.5.0-dev" } + }, + + "require-dev": { + "phpunit/phpunit": "^9.5" } } diff --git a/phpunit.xml b/phpunit.xml index 725a7e7..da9d5a5 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,28 +1,14 @@ - - - - - - ./test - - - - - - ./src - - + + + + ./src + + + + + ./test + + - diff --git a/src/AbstractSnapshot.php b/src/AbstractSnapshot.php index 7c677e9..72758c4 100644 --- a/src/AbstractSnapshot.php +++ b/src/AbstractSnapshot.php @@ -104,15 +104,6 @@ final public function getDataKeys() return array_keys($this->getComparableData()); } - /** - * Clone this object - * - * @codeCoverageIgnore - */ - final private function __clone() - { - } - /** {@inheritDoc} */ final public function offsetExists($offset) { diff --git a/src/Set.php b/src/Set.php index 4ea6296..e05117a 100644 --- a/src/Set.php +++ b/src/Set.php @@ -25,8 +25,6 @@ use Totem\Change\Addition; use Totem\Change\Modification; -use Totem\SetInterface; -use Totem\AbstractSnapshot; use Totem\Snapshot\CollectionSnapshot; /** diff --git a/src/SetInterface.php b/src/SetInterface.php index 19c21fe..a0e1f4c 100644 --- a/src/SetInterface.php +++ b/src/SetInterface.php @@ -11,8 +11,6 @@ namespace Totem; -use Totem\AbstractSnapshot; - /** * Represents a set of changes between two data * diff --git a/test/AbstractChangeTest.php b/test/AbstractChangeTest.php index 9d35e8d..8864e7f 100644 --- a/test/AbstractChangeTest.php +++ b/test/AbstractChangeTest.php @@ -11,14 +11,14 @@ namespace Totem; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; -class AbstractChangeTest extends PHPUnit_Framework_TestCase +class AbstractChangeTest extends TestCase { /** @var Totem\AbstractChange */ private $mock; - public function setUp() + protected function setUp(): void { $this->mock = $this->getMockForAbstractClass('Totem\\AbstractChange', ['old', 'new']); } diff --git a/test/AbstractSnapshotTest.php b/test/AbstractSnapshotTest.php index 7253425..446f01d 100644 --- a/test/AbstractSnapshotTest.php +++ b/test/AbstractSnapshotTest.php @@ -11,29 +11,29 @@ namespace Totem; +use BadMethodCallException; +use InvalidArgumentException; +use PHPUnit\Framework\TestCase; use ReflectionMethod; use ReflectionProperty; +use Totem\Exception\IncomparableDataException; -use PHPUnit_Framework_TestCase; - -class AbstractSnapshotTest extends PHPUnit_Framework_TestCase +class AbstractSnapshotTest extends TestCase { - /** - * @expectedException Totem\Exception\IncomparableDataException - * @expectedExceptionMessage This data is not comparable with the base - */ public function testDiffIncomparable() { + $this->expectException(IncomparableDataException::class); + $this->expectExceptionMessage('This data is not comparable with the base'); + $snapshot = new Snapshot(['comparable' => false]); $snapshot->diff($snapshot); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage The computed data is not an array, "string" given - */ public function testComparableDataFailure() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The computed data is not an array, "string" given'); + $snapshot = new Snapshot(['data' => 'foo']); $snapshot->getComparableData(); } @@ -53,32 +53,29 @@ public function existsProvider() ['bar', false]]; } - /** - * @expectedException BadMethodCallException - * @expectedExceptionMessage A snapshot is frozen by nature - */ public function testOffsetUnset() { + $this->expectException(BadMethodCallException::class); + $this->expectExceptionMessage('A snapshot is frozen by nature'); + $snapshot = new Snapshot(['data' => ['foo' => 'bar']]); unset($snapshot['foo']); } - /** - * @expectedException BadMethodCallException - * @expectedExceptionMessage A snapshot is frozen by nature - */ public function testOffsetSet() { + $this->expectException(BadMethodCallException::class); + $this->expectExceptionMessage('A snapshot is frozen by nature'); + $snapshot = new Snapshot(['data' => ['foo' => 'bar']]); $snapshot[] = 'foo'; } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage The computed data is not an array, "string" given - */ public function testInvalidDataNormalizer() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('The computed data is not an array, "string" given'); + $snapshot = new Snapshot(['data' => 'foo']); $refl = new ReflectionMethod('Totem\\AbstractSnapshot', 'normalize'); @@ -89,7 +86,7 @@ public function testInvalidDataNormalizer() /** @dataProvider normalizerProvider */ public function testNormalizer($data, $snapshotClass, $setClass = null) { - $snapshot = new Snapshot; + $snapshot = new Snapshot(); $setClass = $setClass ?: 'stdClass'; $dataProperty = new ReflectionProperty('Totem\\AbstractSnapshot', 'data'); @@ -110,7 +107,7 @@ public function testNormalizer($data, $snapshotClass, $setClass = null) public function normalizerProvider() { - return [[new Snapshot, 'Totem\\Snapshot', 'Totem\\Set'], + return [[new Snapshot(), 'Totem\\Snapshot', 'Totem\\Set'], [['foo' => 'bar'], 'Totem\\Snapshot\\ArraySnapshot'], [(object) ['foo' => 'bar'], 'Totem\\Snapshot\\ObjectSnapshot']]; } @@ -126,14 +123,15 @@ public function testCorrectSetClass() { $snapshot = new Snapshot(['data' => []]); $snapshot->setSetClass('Totem\\Set'); + + self::assertInstanceOf(Snapshot::class, $snapshot); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage A Set Class should be instantiable and implement Totem\SetInterface - */ public function testWrongSetClass() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('A Set Class should be instantiable and implement Totem\SetInterface'); + $snapshot = new Snapshot(['data' => []]); $snapshot->setSetClass('stdclass'); } diff --git a/test/Change/AdditionTest.php b/test/Change/AdditionTest.php index 0715b30..e7a17d9 100644 --- a/test/Change/AdditionTest.php +++ b/test/Change/AdditionTest.php @@ -11,11 +11,13 @@ namespace Totem\Change; -class AdditionTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class AdditionTest extends TestCase { private $change; - public function setUp() + protected function setUp(): void { $this->change = new Addition('new'); } diff --git a/test/Change/ModificationTest.php b/test/Change/ModificationTest.php index 8520877..ba7279e 100644 --- a/test/Change/ModificationTest.php +++ b/test/Change/ModificationTest.php @@ -11,11 +11,13 @@ namespace Totem\Change; -class ModificationTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class ModificationTest extends TestCase { private $change; - public function setUp() + protected function setUp(): void { $this->change = new Modification('old', 'new'); } diff --git a/test/Change/RemovalTest.php b/test/Change/RemovalTest.php index 079dba5..cf7474d 100644 --- a/test/Change/RemovalTest.php +++ b/test/Change/RemovalTest.php @@ -11,11 +11,13 @@ namespace Totem\Change; -class RemovalTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class RemovalTest extends TestCase { private $change; - public function setUp() + protected function setUp(): void { $this->change = new Removal('old'); } diff --git a/test/SetTest.php b/test/SetTest.php index 65cc3c1..1875a45 100644 --- a/test/SetTest.php +++ b/test/SetTest.php @@ -11,22 +11,23 @@ namespace Totem; +use BadMethodCallException; +use OutOfBoundsException; +use PHPUnit\Framework\TestCase; +use RuntimeException; use stdClass; - -use PHPUnit_Framework_TestCase; - use Totem\Snapshot\ArraySnapshot; use Totem\Snapshot\ObjectSnapshot; use Totem\Snapshot\CollectionSnapshot; -class SetTest extends \PHPUnit_Framework_TestCase +class SetTest extends TestCase { /** * @dataProvider invalidEntryProvider */ public function testSetChangesWithChangedStructure($old, $new, $class) { - $set = new Set; + $set = new Set(); $set->compute(new Snapshot(['data' => $old]), new Snapshot(['data' => $new])); $this->assertInstanceOf('Totem\\Change\\' . $class, $set->getChange('1')); @@ -43,7 +44,7 @@ public function testHasChanged() $old = new Snapshot(['data' => ['foo' => 'bar', 'baz' => 'fubar']]); $new = new Snapshot(['data' => ['foo' => 'bar', 'baz' => 'fubaz']]); - $set = new Set; + $set = new Set(); $set->compute($old, $new); $this->assertFalse($set->hasChanged('foo')); @@ -52,14 +53,13 @@ public function testHasChanged() $this->assertTrue(isset($set['baz'])); } - /** - * @expectedException OutOfBoundsException - */ public function testGetChangeWithInvalidProperty() { + $this->expectException(OutOfBoundsException::class); + $old = new Snapshot(['data' => ['foo' => 'bar']]); - $set = new Set; + $set = new Set(); $set->compute($old, $old); $set->getChange('foo'); @@ -68,7 +68,7 @@ public function testGetChangeWithInvalidProperty() // @todo to break up public function testGetChange() { - $o = [new stdClass, (object) ['foo' => 'bar']]; + $o = [new stdClass(), (object) ['foo' => 'bar']]; $old = $new = ['foo' => 'foo', 'bar' => new ArraySnapshot(['foo', 'bar']), @@ -92,7 +92,7 @@ public function testGetChange() $new['kludge'] = 42; $new['xyzzy'] = (object) []; - $set = new Set; + $set = new Set(); $set->compute(new Snapshot(['data' => $old]), new Snapshot(['data' => $new])); $this->assertInstanceOf('Totem\\Change\\Modification', $set->getChange('fuqux')); @@ -107,63 +107,58 @@ public function testGetChange() public function testIterator() { - $set = new Set; + $set = new Set(); $set->compute(new Snapshot(['data' => ['foo']]), new Snapshot(['data' => ['bar']])); $this->assertInstanceOf('ArrayIterator', $set->getIterator()); } - /** - * @expectedException BadMethodCallException - */ public function testForbidenSetter() { - $set = new Set; - $old = new Snapshot; + $this->expectException(BadMethodCallException::class); + + $set = new Set(); + $old = new Snapshot(); $set->compute($old, $old); $set[] = 'baz'; } - /** - * @expectedException BadMethodCallException - */ public function testForbidenUnsetter() { - $set = new Set; - $old = new Snapshot; + $this->expectException(BadMethodCallException::class); + + $set = new Set(); + $old = new Snapshot(); $set->compute($old, $old); unset($set[0]); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage The changeset was not computed yet ! - */ public function testHasChangedNotComputedShouldThrowException() { - $set = new Set; + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('The changeset was not computed yet !'); + + $set = new Set(); $set->hasChanged('foo'); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage The changeset was not computed yet ! - */ public function testNotComputedCountShouldThrowException() { - $set = new Set; + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('The changeset was not computed yet !'); + + $set = new Set(); count($set); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage The changeset was not computed yet ! - */ public function testNotComputedIteratorShouldThrowException() { - $set = new Set; + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('The changeset was not computed yet !'); + + $set = new Set(); $set->getIterator(); } @@ -190,7 +185,7 @@ public function testComputeCollections() $old = new CollectionSnapshot($old, '[foo]'); $new = new CollectionSnapshot($new, '[foo]'); - $set = new Set; + $set = new Set(); $set->compute($old, $new); $this->assertContainsOnly('integer', array_keys(iterator_to_array($set))); @@ -199,7 +194,7 @@ public function testComputeCollections() /** @dataProvider unaffectedSnapshotComputerProvider */ public function testUnaffectedCollections(AbstractSnapshot $origin, AbstractSnapshot $upstream) { - $set = new Set; + $set = new Set(); $set->compute($origin, $upstream); $this->assertNotContainsOnly('integer',array_keys(iterator_to_array($set))); diff --git a/test/Snapshot/ArraySnapshotTest.php b/test/Snapshot/ArraySnapshotTest.php index c640368..091d742 100644 --- a/test/Snapshot/ArraySnapshotTest.php +++ b/test/Snapshot/ArraySnapshotTest.php @@ -11,12 +11,9 @@ namespace Totem\Snapshot; -use stdClass; -use ReflectionMethod; +use PHPUnit\Framework\TestCase; -use PHPUnit_Framework_TestCase; - -class ArraySnapshotTest extends PHPUnit_Framework_TestCase +class ArraySnapshotTest extends TestCase { /** * @dataProvider providerCompare @@ -42,6 +39,8 @@ public function providerCompare() */ public function testDeepConstructor($value) { + $this->expectNotToPerformAssertions(); + new ArraySnapshot(['foo' => $value]); } diff --git a/test/Snapshot/CollectionSnapshotTest.php b/test/Snapshot/CollectionSnapshotTest.php index fa6e9f7..f0a5313 100644 --- a/test/Snapshot/CollectionSnapshotTest.php +++ b/test/Snapshot/CollectionSnapshotTest.php @@ -12,38 +12,40 @@ namespace Totem\Snapshot; use ArrayObject; +use InvalidArgumentException; +use PHPUnit\Framework\TestCase; use ReflectionProperty; -use PHPUnit_Framework_TestCase; - -class CollectionSnapshotTest extends PHPUnit_Framework_TestCase +class CollectionSnapshotTest extends TestCase { - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage An array or a Traversable was expected to take a snapshot of a collection, "string" given - */ public function testSnapshotNotArray() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage( + 'An array or a Traversable was expected to take a snapshot of a collection, "string" given' + ); + new CollectionSnapshot('foo', 'bar', ['snapshotClass' => 'Totem\\Snapshot']); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage The snapshot class "Totem\Fubar" does not seem to be loadable - */ public function testSnapshotClassNotLoadable() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('The snapshot class "Totem\Fubar" does not seem to be loadable'); + new CollectionSnapshot('foo', 'bar', ['snapshotClass' => 'Totem\\Fubar']); } /** * @dataProvider snapshotClassWrongReflectionProvider - * - * @expectedException InvalidArgumentException - * @expectedExceptionMessage A Snapshot Class should be instantiable and extends abstract class Totem\AbstractSnapshot */ public function testSnapshotWrongReflection($class) { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage( + 'A Snapshot Class should be instantiable and extends abstract class Totem\AbstractSnapshot' + ); + new CollectionSnapshot('foo', 'bar', ['snapshotClass' => $class]); } @@ -53,21 +55,23 @@ public function snapshotClassWrongReflectionProvider() ['stdClass']]; } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage The given array / Traversable is not a collection as it contains non numeric keys - */ public function testNonCollection() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage( + 'The given array / Traversable is not a collection as it contains non numeric keys' + ); + new CollectionSnapshot(new ArrayObject(['foo' => 'bar']), 'bar'); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage The key "baz" is not defined or readable in one of the elements of the collection - */ public function testKeyNotReadable() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage( + 'The key "baz" is not defined or readable in one of the elements of the collection' + ); + new CollectionSnapshot([['foo' => 'bar']], 'baz'); } @@ -97,12 +101,11 @@ public function allValidProvider() [false]]; } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage The primary key "baz" is not in the computed dataset - */ public function testOriginalKeyNotFound() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('The primary key "baz" is not in the computed dataset'); + $snapshot = new CollectionSnapshot([['foo' => 'bar']], '[foo]'); $snapshot->getOriginalKey('baz'); } diff --git a/test/Snapshot/ObjectSnapshotTest.php b/test/Snapshot/ObjectSnapshotTest.php index fbaf2f1..8f84db5 100644 --- a/test/Snapshot/ObjectSnapshotTest.php +++ b/test/Snapshot/ObjectSnapshotTest.php @@ -11,12 +11,11 @@ namespace Totem\Snapshot; +use InvalidArgumentException; +use PHPUnit\Framework\TestCase; use stdClass; -use ReflectionMethod; -use PHPUnit_Framework_TestCase; - -class ObjectSnapshotTest extends PHPUnit_Framework_TestCase +class ObjectSnapshotTest extends TestCase { /** * @dataProvider providerCompare @@ -29,7 +28,7 @@ public function testCompare($object, $compare, $expect) public function providerCompare() { - $object = new stdClass; + $object = new stdClass(); $snapshot = $this->getMockBuilder('Totem\\AbstractSnapshot') ->disableOriginalConstructor() @@ -40,11 +39,10 @@ public function providerCompare() [$object, $snapshot, false]]; } - /** - * @expectedException InvalidArgumentException - */ public function testConstructWithoutObject() { + $this->expectException(InvalidArgumentException::class); + new ObjectSnapshot([]); } @@ -96,4 +94,3 @@ public function __construct($foo, $bar, $baz) } } -