diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index a668078..fc6cd7a 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -33,10 +33,10 @@ jobs: run: composer install --prefer-dist --no-progress - name: Run CS - run: vendor/bin/phpcs -p --extensions=php ./src ./tests + run: vendor/bin/phpcs - name: Run stan - run: vendor/bin/phpstan analyse ./src --level 4 + run: vendor/bin/phpstan analyse - name: Run tests run: vendor/bin/phpunit --coverage-clover=coverage.xml diff --git a/.gitignore b/.gitignore index 98aab43..a192a98 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /nbproject /phpunit.xml /coverage.xml +.phpunit.* diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0b92138..0000000 --- a/.travis.yml +++ /dev/null @@ -1,44 +0,0 @@ -language: php - -dist: trusty - -sudo: false - -php: - - 5.6 - - 7.0 - - 7.1 - -env: - global: - - DEFAULT=1 - -matrix: - fast_finish: true - - include: - - php: 5.6 - env: PHPCS=1 DEFAULT=0 - - php: 7.1 - env: PHPSTAN=4 DEFAULT=0 - - php: 7.1 - env: PHPSTAN=7 DEFAULT=0 - - allow_failures: - - env: PHPCS=1 DEFAULT=0 - - env: PHPSTAN=7 DEFAULT=0 - -before_script: - - composer install; - - if [[ $PHPSTAN > 0 ]]; then composer require phpstan/phpstan:^0.7; fi - -script: - - if [[ $DEFAULT = 1 ]]; then vendor/bin/phpunit --coverage-clover=coverage.xml; fi - - if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -p --extensions=php ./src ./tests; fi - - if [[ $PHPSTAN > 0 ]]; then vendor/bin/phpstan analyse ./src --level $PHPSTAN; fi - -notifications: - email: false - -after_success: - - bash <(curl -s https://codecov.io/bash) diff --git a/composer.json b/composer.json index 457a990..fbbc832 100644 --- a/composer.json +++ b/composer.json @@ -5,13 +5,13 @@ "type": "cakephp-plugin", "license": "MIT", "require": { - "php": ">=5.6", - "cakephp/orm": "^3.4" + "cakephp/orm": "~4.0" }, "require-dev": { - "cakephp/cakephp": "~3.4.0", - "cakephp/cakephp-codesniffer": "^3.0", - "phpunit/phpunit": "^5.6|^6" + "cakephp/cakephp": "~4.0", + "cakephp/cakephp-codesniffer": "^4.0", + "phpunit/phpunit": "^9.5", + "phpstan/phpstan": "^2.0" }, "autoload": { "psr-4": { @@ -23,5 +23,10 @@ "Cake\\Test\\": "vendor/cakephp/cakephp/tests", "Robotusers\\Chunk\\Test\\": "tests" } + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 36805de..d09769c 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -1,4 +1,16 @@ - - + + + + + + + + + + + + + src/ + tests/ diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..86901ed --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,7 @@ +parameters: + level: 4 +# reportUnmatchedIgnoredErrors: false +# treatPhpDocTypesAsCertain: false + paths: + - src/ + - tests/ \ No newline at end of file diff --git a/src/Model/Behavior/ChunkBehavior.php b/src/Model/Behavior/ChunkBehavior.php index 2ad8d19..1c046c6 100644 --- a/src/Model/Behavior/ChunkBehavior.php +++ b/src/Model/Behavior/ChunkBehavior.php @@ -1,4 +1,6 @@ 1000 + 'size' => 1000, ]; /** * Constructor. * - * @param Query $query Query object. + * @param \Cake\ORM\Query $query Query object. * @param array $config Configuration. - * @throws RuntimeException When query is not supported. + * @throws \RuntimeException When query is not supported. */ public function __construct(Query $query, array $config = []) { @@ -140,34 +142,36 @@ public function __construct(Query $query, array $config = []) } /** - * {@inheritDoc} + * @inheritDoc */ + #[\ReturnTypeWillChange] public function current() { return $this->current; } /** - * {@inheritDoc} + * @inheritDoc */ + #[\ReturnTypeWillChange] public function key() { return $this->index; } /** - * {@inheritDoc} + * @inheritDoc */ - public function next() + public function next(): void { $this->index++; $this->chunkIndex++; } /** - * {@inheritDoc} + * @inheritDoc */ - public function rewind() + public function rewind(): void { $this->index = 0; $this->page = 1; @@ -176,9 +180,9 @@ public function rewind() } /** - * {@inheritDoc} + * @inheritDoc */ - public function valid() + public function valid(): bool { if ($this->limit && $this->index >= $this->limit) { return false; @@ -235,30 +239,40 @@ protected function fetchChunk() } /** - * {@inheritDoc} + * @inheritDoc */ - public function count() + public function count(): int { throw new RuntimeException('Count is not supported yet.'); } /** - * Serialization is not supported (yet). - * * {@inheritDoc} + * + * Serialization is not supported (yet). * */ public function serialize() { throw new RuntimeException('You cannot serialize this result set.'); } + public function __serialize(): array + { + throw new RuntimeException('You cannot serialize this result set.'); + } + /** - * Serialization is not supported (yet). - * * {@inheritDoc} + * + * Serialization is not supported (yet). * */ public function unserialize($serialized) { throw new RuntimeException('You cannot unserialize this result set.'); } + + public function __unserialize(array $data): void + { + throw new RuntimeException('You cannot unserialize this result set.'); + } } diff --git a/tests/TestCase/Model/Behavior/ChunkBehaviorTest.php b/tests/TestCase/Model/Behavior/ChunkBehaviorTest.php index 88f5bb9..3cde097 100644 --- a/tests/TestCase/Model/Behavior/ChunkBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/ChunkBehaviorTest.php @@ -1,4 +1,6 @@ chunk($query, [ - 'size' => 100 + 'size' => 100, ]); $this->assertInstanceOf(ResultSet::class, $chunk); diff --git a/tests/TestCase/ORM/ResultSetTest.php b/tests/TestCase/ORM/ResultSetTest.php index b71d920..574a7f9 100644 --- a/tests/TestCase/ORM/ResultSetTest.php +++ b/tests/TestCase/ORM/ResultSetTest.php @@ -1,4 +1,6 @@ */ -class ResultsSetTest extends TestCase +class ResultSetTest extends TestCase { public $fixtures = [ - 'core.authors' + 'core.Authors', ]; public function testSameResults() @@ -48,7 +51,7 @@ public function testSameResults() $standardResults = $query->all(); $chunkedResults = new ResultSet($query, [ - 'size' => 1 + 'size' => 1, ]); $this->assertEquals($standardResults->toArray(), $chunkedResults->toArray()); @@ -66,7 +69,7 @@ public function testMultipleQueriesFired() }); $results = new ResultSet($query, [ - 'size' => 1 + 'size' => 1, ]); $results->toList(); @@ -82,18 +85,17 @@ public function testLimitAndOffset() $standardResults = $query->all(); $chunkedResults = new ResultSet($query, [ - 'size' => 1 + 'size' => 1, ]); $this->assertEquals($standardResults->toArray(), $chunkedResults->toArray()); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage You cannot serialize this result set. - */ public function testSerialize() { + $this->expectException(RuntimeException::class); + $this->expectErrorMessage('You cannot serialize this result set.'); + $table = TableRegistry::get('Authors'); $query = $table->find(); @@ -101,12 +103,11 @@ public function testSerialize() $chunkedResults->serialize(); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage You cannot unserialize this result set. - */ public function testUnserialize() { + $this->expectException(RuntimeException::class); + $this->expectErrorMessage('You cannot unserialize this result set.'); + $table = TableRegistry::get('Authors'); $query = $table->find(); @@ -114,12 +115,11 @@ public function testUnserialize() $chunkedResults->unserialize(''); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage Count is not supported yet. - */ public function testCount() { + $this->expectException(RuntimeException::class); + $this->expectErrorMessage('Count is not supported yet.'); + $table = TableRegistry::get('Authors'); $query = $table->find(); @@ -127,12 +127,11 @@ public function testCount() $chunkedResults->count(); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage You cannot chunk a non-select query. - */ public function testInvalidQuery() { + $this->expectException(RuntimeException::class); + $this->expectErrorMessage('You cannot chunk a non-select query.'); + $table = TableRegistry::get('Authors'); $query = $table->query()->insert(['foo' => 'bar']); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 1c2790c..eac92ad 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,4 +1,6 @@ PLUGIN_ROOT . DS -]); +Plugin::getCollection()->add(new BasePlugin([ + 'name' => 'Robotusers/Chunk', + 'path' => PLUGIN_ROOT . DS, +]));