From 85e1e53b35f746152f44b54f7b5bdc3a95bcc760 Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Thu, 16 Jul 2020 14:40:36 -0500 Subject: [PATCH 01/18] Updated psalm to 3.12.3 --- composer.json | 2 +- src/Collection/CollectionTrait.php | 1 + src/Database/Type/ExpressionTypeCasterTrait.php | 2 +- src/ORM/Behavior/Translate/EavStrategy.php | 1 + src/ORM/Behavior/Translate/ShadowTableStrategy.php | 1 + src/TestSuite/Constraint/Response/StatusCodeBase.php | 1 + src/TestSuite/IntegrationTestTrait.php | 1 + 7 files changed, 7 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 22a70a687c9..cb1091bc4bc 100644 --- a/composer.json +++ b/composer.json @@ -112,7 +112,7 @@ "@phpstan", "@psalm" ], - "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^0.12 psalm/phar:~3.11.2 && mv composer.backup composer.json" + "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^0.12 psalm/phar:~3.12.2 && mv composer.backup composer.json" }, "config": { "sort-packages": true, diff --git a/src/Collection/CollectionTrait.php b/src/Collection/CollectionTrait.php index f2d50cfec61..b1fb4192537 100644 --- a/src/Collection/CollectionTrait.php +++ b/src/Collection/CollectionTrait.php @@ -626,6 +626,7 @@ public function nest($idPath, $parentPath, string $nestingKey = 'children'): Col } if (empty($key) || !isset($parents[$key])) { foreach ($values as $id) { + /** @psalm-suppress PossiblyInvalidArgument */ $parents[$id] = $isObject ? $parents[$id] : new ArrayIterator($parents[$id], 1); $mapReduce->emit($parents[$id]); } diff --git a/src/Database/Type/ExpressionTypeCasterTrait.php b/src/Database/Type/ExpressionTypeCasterTrait.php index 2743b42f83e..02090aa2c23 100644 --- a/src/Database/Type/ExpressionTypeCasterTrait.php +++ b/src/Database/Type/ExpressionTypeCasterTrait.php @@ -49,7 +49,7 @@ protected function _castToExpression($value, ?string $type = null) $multi = $type !== $baseType; if ($multi) { - /** @psalm-suppress InvalidArgument */ + /** @var \Cake\Database\Type\ExpressionTypeInterface $converter */ return array_map([$converter, 'toExpression'], $value); } diff --git a/src/ORM/Behavior/Translate/EavStrategy.php b/src/ORM/Behavior/Translate/EavStrategy.php index 730a873713b..e36bc68999b 100644 --- a/src/ORM/Behavior/Translate/EavStrategy.php +++ b/src/ORM/Behavior/Translate/EavStrategy.php @@ -380,6 +380,7 @@ protected function rowMapper($results, $locale) $row['_locale'] = $locale; if ($hydrated) { + /** @psalm-suppress PossiblyInvalidMethodCall */ $row->clean(); } diff --git a/src/ORM/Behavior/Translate/ShadowTableStrategy.php b/src/ORM/Behavior/Translate/ShadowTableStrategy.php index 6c993e49eab..1e60a49b6e1 100644 --- a/src/ORM/Behavior/Translate/ShadowTableStrategy.php +++ b/src/ORM/Behavior/Translate/ShadowTableStrategy.php @@ -483,6 +483,7 @@ protected function rowMapper($results, $locale) unset($row['translation']); if ($hydrated) { + /** @psalm-suppress PossiblyInvalidMethodCall */ $row->clean(); } diff --git a/src/TestSuite/Constraint/Response/StatusCodeBase.php b/src/TestSuite/Constraint/Response/StatusCodeBase.php index 5e4fc70b868..d68c38576b8 100644 --- a/src/TestSuite/Constraint/Response/StatusCodeBase.php +++ b/src/TestSuite/Constraint/Response/StatusCodeBase.php @@ -67,6 +67,7 @@ protected function statusCodeBetween(int $min, int $max): bool */ protected function failureDescription($other): string { + /** @psalm-suppress InternalMethod */ return $this->toString(); } } diff --git a/src/TestSuite/IntegrationTestTrait.php b/src/TestSuite/IntegrationTestTrait.php index 45195dc2530..75f2176f0e7 100644 --- a/src/TestSuite/IntegrationTestTrait.php +++ b/src/TestSuite/IntegrationTestTrait.php @@ -692,6 +692,7 @@ protected function _castToString(array $data): array { foreach ($data as $key => $value) { if (is_scalar($value)) { + /** @psalm-suppress RedundantCondition */ $data[$key] = $value === false ? '0' : (string)$value; continue; From a84ff95833f74f521803f84520e7c6ca6d3ed460 Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Fri, 17 Jul 2020 12:29:56 -0500 Subject: [PATCH 02/18] Change @var to @psalm-var to avoid IDE issues --- src/Database/Type/ExpressionTypeCasterTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/Type/ExpressionTypeCasterTrait.php b/src/Database/Type/ExpressionTypeCasterTrait.php index 02090aa2c23..d15cfde52e0 100644 --- a/src/Database/Type/ExpressionTypeCasterTrait.php +++ b/src/Database/Type/ExpressionTypeCasterTrait.php @@ -49,7 +49,7 @@ protected function _castToExpression($value, ?string $type = null) $multi = $type !== $baseType; if ($multi) { - /** @var \Cake\Database\Type\ExpressionTypeInterface $converter */ + /** @psalm-var \Cake\Database\Type\ExpressionTypeInterface $converter */ return array_map([$converter, 'toExpression'], $value); } From 01ef3564a57ac47d57fa748f5feb1b54a50bb7d9 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Fri, 17 Jul 2020 18:24:40 -0400 Subject: [PATCH 03/18] Throw an error when the csrfToken attribute is already set When the request already contains a csrfToken adding another one causes token mismatches. Raising an exception when we hit this scenario should help the developer figure out why they are seeing CSRF failures and give them suggestions on where to look for the extra CSRF middleware layer. --- .../Middleware/CsrfProtectionMiddleware.php | 9 ++++++++ .../CsrfProtectionMiddlewareTest.php | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/Http/Middleware/CsrfProtectionMiddleware.php b/src/Http/Middleware/CsrfProtectionMiddleware.php index 79de64091e9..d1bbffdc173 100644 --- a/src/Http/Middleware/CsrfProtectionMiddleware.php +++ b/src/Http/Middleware/CsrfProtectionMiddleware.php @@ -27,6 +27,7 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; +use RuntimeException; /** * Provides CSRF protection & validation. @@ -122,6 +123,14 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface return $handler->handle($request); } + if ($request->getAttribute('csrfToken')) { + throw new RuntimeException( + 'A CSRF token is already set in the request.' . + "\n" . + 'Ensure you do not have the CSRF middleware applied more than once. ' . + 'Check both your `Application::middleware()` method and `config/routes.php`.' + ); + } $cookies = $request->getCookieParams(); $cookieData = Hash::get($cookies, $this->_config['cookieName']); diff --git a/tests/TestCase/Http/Middleware/CsrfProtectionMiddlewareTest.php b/tests/TestCase/Http/Middleware/CsrfProtectionMiddlewareTest.php index 485678800b8..ed4cef4d846 100644 --- a/tests/TestCase/Http/Middleware/CsrfProtectionMiddlewareTest.php +++ b/tests/TestCase/Http/Middleware/CsrfProtectionMiddlewareTest.php @@ -26,6 +26,7 @@ use Laminas\Diactoros\Response as DiactorosResponse; use Laminas\Diactoros\Response\RedirectResponse; use Psr\Http\Message\ServerRequestInterface; +use RuntimeException; use TestApp\Http\TestRequestHandler; /** @@ -143,6 +144,26 @@ public function testRedirectResponseCookies() $this->assertStringContainsString('csrfToken=', $response->getHeaderLine('Set-Cookie')); } + /** + * Test that double applying CSRF causes a failure. + * + * @return void + */ + public function testDoubleApplicationFailure() + { + $request = new ServerRequest([ + 'environment' => ['REQUEST_METHOD' => 'GET'], + ]); + $request = $request->withAttribute('csrfToken', 'not-good'); + $handler = new TestRequestHandler(function () { + return new RedirectResponse('/'); + }); + + $middleware = new CsrfProtectionMiddleware(); + $this->expectException(RuntimeException::class); + $middleware->process($request, $handler); + } + /** * Test that the CSRF tokens are set for diactoros responses * From 5f36d7877fa163c2ab1eaa4c883ee65c8ef332ff Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 18 Jul 2020 22:08:11 -0400 Subject: [PATCH 04/18] Update formatting to improve compatibility Some versions of make don't like the multiline json. --- Makefile | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 5a431eac5a1..102a2bae6ab 100644 --- a/Makefile +++ b/Makefile @@ -143,12 +143,7 @@ package: clean dist/cakephp-$(DASH_VERSION).zip publish: guard-VERSION dist/cakephp-$(DASH_VERSION).zip @echo "Creating draft release for $(VERSION). prerelease=$(PRERELEASE)" - curl $(AUTH) -XPOST $(API_HOST)/repos/$(OWNER)/cakephp/releases -d '{ - "tag_name": "$(VERSION)", - "name": "CakePHP $(VERSION) released", - "draft": true, - "prerelease": $(PRERELEASE) - }' > release.json + curl $(AUTH) -XPOST $(API_HOST)/repos/$(OWNER)/cakephp/releases -d '{"tag_name": "$(VERSION)", "name": "CakePHP $(VERSION) released", "draft": true, "prerelease": $(PRERELEASE)}' > release.json # Extract id out of response json. php -r '$$f = file_get_contents("./release.json"); \ $$d = json_decode($$f, true); \ @@ -180,10 +175,7 @@ component-%: tag-component-%: component-% guard-VERSION guard-GITHUB_TOKEN @echo "Creating tag for the $* component" git checkout $* - curl $(AUTH) -XPOST $(API_HOST)/repos/$(OWNER)/$*/git/refs -d '{ - "ref": "refs\/tags\/$(VERSION)", - "sha": "$(shell git rev-parse $*)" - }' + curl $(AUTH) -XPOST $(API_HOST)/repos/$(OWNER)/$*/git/refs -d '{"ref": "refs\/tags\/$(VERSION)", "sha": "$(shell git rev-parse $*)"}' git checkout $(CURRENT_BRANCH) > /dev/null git branch -D $* git remote rm $* From ec1afe59755717c25492bdb50efcd5f06fe52c0b Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 18 Jul 2020 22:28:50 -0400 Subject: [PATCH 05/18] Update version number to 4.1.1 --- VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION.txt b/VERSION.txt index 87c20f19ead..69173bbb35a 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -16,4 +16,4 @@ // @license https://opensource.org/licenses/mit-license.php MIT License // +--------------------------------------------------------------------------------------------+ // //////////////////////////////////////////////////////////////////////////////////////////////////// -4.1.0 +4.1.1 From 73384c3d4fe3b39a62e3741442b27934d9e31763 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 18 Jul 2020 23:50:57 -0400 Subject: [PATCH 06/18] Fix another make compatibility issue. --- Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 102a2bae6ab..3fdf74d2ef7 100644 --- a/Makefile +++ b/Makefile @@ -145,9 +145,7 @@ publish: guard-VERSION dist/cakephp-$(DASH_VERSION).zip @echo "Creating draft release for $(VERSION). prerelease=$(PRERELEASE)" curl $(AUTH) -XPOST $(API_HOST)/repos/$(OWNER)/cakephp/releases -d '{"tag_name": "$(VERSION)", "name": "CakePHP $(VERSION) released", "draft": true, "prerelease": $(PRERELEASE)}' > release.json # Extract id out of response json. - php -r '$$f = file_get_contents("./release.json"); \ - $$d = json_decode($$f, true); \ - file_put_contents("./id.txt", $$d["id"]);' + php -r '$$f = file_get_contents("./release.json"); $$d = json_decode($$f, true); file_put_contents("./id.txt", $$d["id"]);' @echo "Uploading zip file to github." curl $(AUTH) -XPOST \ $(UPLOAD_HOST)/repos/$(OWNER)/cakephp/releases/`cat ./id.txt`/assets?name=cakephp-$(DASH_VERSION).zip \ From dd8d22c776b1da20929c439abb7fc2da2fcdebf0 Mon Sep 17 00:00:00 2001 From: othercorey Date: Sun, 19 Jul 2020 17:13:53 -0500 Subject: [PATCH 07/18] Use postgresql 9.6 for travis builds --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 6ff78760086..1c2f25e1bdd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,9 @@ services: - postgresql - mysql +addons: + postgresql: '9.6' + cache: directories: - $HOME/.composer/cache From 48d6eddca0cbf46521974feb2575e48f05184272 Mon Sep 17 00:00:00 2001 From: ADmad Date: Mon, 20 Jul 2020 23:06:41 +0530 Subject: [PATCH 08/18] Update use of deprecated class name. --- src/Database/Expression/TupleComparison.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/Expression/TupleComparison.php b/src/Database/Expression/TupleComparison.php index 322e01fd7e1..45aac11e47b 100644 --- a/src/Database/Expression/TupleComparison.php +++ b/src/Database/Expression/TupleComparison.php @@ -24,7 +24,7 @@ * This expression represents SQL fragments that are used for comparing one tuple * to another, one tuple to a set of other tuples or one tuple to an expression */ -class TupleComparison extends Comparison +class TupleComparison extends ComparisonExpression { /** * The type to be used for casting the value to a database representation From 7e4d7d13217190a5771ed8da6eec6a466407d2d8 Mon Sep 17 00:00:00 2001 From: mcsknp Date: Tue, 21 Jul 2020 10:47:06 +0900 Subject: [PATCH 09/18] check datatype for localizedTime cakephp#14800 --- src/Validation/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Validation/Validation.php b/src/Validation/Validation.php index 0d7b159824c..ee0e638d412 100644 --- a/src/Validation/Validation.php +++ b/src/Validation/Validation.php @@ -658,7 +658,7 @@ public static function localizedTime($check, string $type = 'datetime', $format if ($check instanceof DateTimeInterface) { return true; } - if (is_object($check)) { + if (!is_string($check)) { return false; } static $methods = [ From 2ad86f084c80adb77ef01fe1c74745511661654d Mon Sep 17 00:00:00 2001 From: mcsknp Date: Tue, 21 Jul 2020 11:54:50 +0900 Subject: [PATCH 10/18] fix Validation::custom function arguments cakephp#14816 --- src/Validation/Validation.php | 8 ++++++-- tests/TestCase/Validation/ValidationTest.php | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Validation/Validation.php b/src/Validation/Validation.php index 0d7b159824c..aa18c0aba6f 100644 --- a/src/Validation/Validation.php +++ b/src/Validation/Validation.php @@ -436,12 +436,16 @@ public static function containsNonAlphaNumeric($check, int $count = 1): bool /** * Used when a custom regular expression is needed. * - * @param string $check The value to check. + * @param mixed $check The value to check. * @param string|null $regex If $check is passed as a string, $regex must also be set to valid regular expression * @return bool Success */ - public static function custom(string $check, ?string $regex = null): bool + public static function custom($check, ?string $regex = null): bool { + if (!is_string($check)) { + return false; + } + if ($regex === null) { static::$errors[] = 'You must define a regular expression for Validation::custom()'; diff --git a/tests/TestCase/Validation/ValidationTest.php b/tests/TestCase/Validation/ValidationTest.php index db2194bbb2a..3146ffa791d 100644 --- a/tests/TestCase/Validation/ValidationTest.php +++ b/tests/TestCase/Validation/ValidationTest.php @@ -969,6 +969,8 @@ public function testCustom() $this->assertTrue(Validation::custom('12345', '/(?assertFalse(Validation::custom('Text', '/(?assertFalse(Validation::custom('123.45', '/(?assertFalse(Validation::custom(1, '/.*/')); + $this->assertFalse(Validation::custom(['input is not string'], '/.*/')); $this->assertFalse(Validation::custom('missing regex')); } From 725ca399d77b19e515075625c3f695c0f05bc5f9 Mon Sep 17 00:00:00 2001 From: mcsknp Date: Tue, 21 Jul 2020 12:14:50 +0900 Subject: [PATCH 11/18] add test case cakephp#14800 --- tests/TestCase/Validation/ValidationTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/TestCase/Validation/ValidationTest.php b/tests/TestCase/Validation/ValidationTest.php index db2194bbb2a..28134f0016f 100644 --- a/tests/TestCase/Validation/ValidationTest.php +++ b/tests/TestCase/Validation/ValidationTest.php @@ -1759,6 +1759,8 @@ public function testLocalizedTime() $this->assertFalse(Validation::localizedTime('', 'date')); $this->assertFalse(Validation::localizedTime('invalid', 'date')); + $this->assertFalse(Validation::localizedTime(1, 'date')); + $this->assertFalse(Validation::localizedTime(['an array'], 'date')); // English (US) I18n::setLocale('en_US'); From 88aa4cc2e8268c96f9a3711ba22a45573aa5597a Mon Sep 17 00:00:00 2001 From: mcsknp Date: Tue, 21 Jul 2020 14:36:45 +0900 Subject: [PATCH 12/18] cast array key to string cakephp#14810 --- src/Datasource/EntityTrait.php | 1 + src/ORM/Marshaller.php | 1 + tests/TestCase/ORM/EntityTest.php | 7 +++++++ tests/TestCase/ORM/MarshallerTest.php | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/src/Datasource/EntityTrait.php b/src/Datasource/EntityTrait.php index 8a590190ef7..ff931ffff01 100644 --- a/src/Datasource/EntityTrait.php +++ b/src/Datasource/EntityTrait.php @@ -235,6 +235,7 @@ public function set($field, $value = null, array $options = []) $options += ['setter' => true, 'guard' => $guard]; foreach ($field as $name => $value) { + $name = (string) $name; if ($options['guard'] === true && !$this->isAccessible($name)) { continue; } diff --git a/src/ORM/Marshaller.php b/src/ORM/Marshaller.php index b3fc7c96c4f..932e13df5b0 100644 --- a/src/ORM/Marshaller.php +++ b/src/ORM/Marshaller.php @@ -72,6 +72,7 @@ protected function _buildPropertyMap(array $data, array $options): array // Is a concrete column? foreach (array_keys($data) as $prop) { + $prop = (string) $prop; $columnType = $schema->getColumnType($prop); if ($columnType) { $map[$prop] = function ($value, $entity) use ($columnType) { diff --git a/tests/TestCase/ORM/EntityTest.php b/tests/TestCase/ORM/EntityTest.php index 4750b5827be..05d767a1782 100644 --- a/tests/TestCase/ORM/EntityTest.php +++ b/tests/TestCase/ORM/EntityTest.php @@ -69,6 +69,13 @@ public function testSetMultiplePropertiesNoSetters() $this->assertSame(3, $entity->thing); $this->assertSame('bar', $entity->getOriginal('foo')); $this->assertEquals(1, $entity->getOriginal('id')); + + $entity->set(['foo', 'bar']); + $this->assertEquals('foo', $entity->{0}); + $this->assertEquals('bar', $entity->{1}); + + $entity->set(['sample']); + $this->assertEquals('sample', $entity->{0}); } /** diff --git a/tests/TestCase/ORM/MarshallerTest.php b/tests/TestCase/ORM/MarshallerTest.php index 5225eb24e66..d78a83e2932 100644 --- a/tests/TestCase/ORM/MarshallerTest.php +++ b/tests/TestCase/ORM/MarshallerTest.php @@ -132,6 +132,25 @@ public function testOneSimple() $this->assertSame('Articles', $result->getSource()); } + /** + * Test that marshalling an entity with numeric key in data array + * + * @return void + */ + public function testOneWithNumericField() + { + $data = [ + 'sample', + 'username' => 'test', + 'password' => 'secret', + 1, + ]; + $marshall = new Marshaller($this->articles); + $result = $marshall->one($data, []); + $this->assertEquals($data[0], $result->{0}); + $this->assertEquals($data[1], $result->{1}); + } + /** * Test that marshalling an entity with '' for pk values results * in no pk value being set. From 929c38c5ff9e705fd5b85ca1ad5cd9986c4d4308 Mon Sep 17 00:00:00 2001 From: mcsknp Date: Tue, 21 Jul 2020 14:44:43 +0900 Subject: [PATCH 13/18] fix cs error #14810 --- src/Datasource/EntityTrait.php | 2 +- src/ORM/Marshaller.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Datasource/EntityTrait.php b/src/Datasource/EntityTrait.php index ff931ffff01..d556d33157c 100644 --- a/src/Datasource/EntityTrait.php +++ b/src/Datasource/EntityTrait.php @@ -235,7 +235,7 @@ public function set($field, $value = null, array $options = []) $options += ['setter' => true, 'guard' => $guard]; foreach ($field as $name => $value) { - $name = (string) $name; + $name = (string)$name; if ($options['guard'] === true && !$this->isAccessible($name)) { continue; } diff --git a/src/ORM/Marshaller.php b/src/ORM/Marshaller.php index 932e13df5b0..45c3363d61d 100644 --- a/src/ORM/Marshaller.php +++ b/src/ORM/Marshaller.php @@ -72,7 +72,7 @@ protected function _buildPropertyMap(array $data, array $options): array // Is a concrete column? foreach (array_keys($data) as $prop) { - $prop = (string) $prop; + $prop = (string)$prop; $columnType = $schema->getColumnType($prop); if ($columnType) { $map[$prop] = function ($value, $entity) use ($columnType) { From 92b9f1153167c4111e06816aabb12d9bfa8fb871 Mon Sep 17 00:00:00 2001 From: mcsknp Date: Tue, 21 Jul 2020 15:56:23 +0900 Subject: [PATCH 14/18] use get method to get entity property #14810 --- tests/TestCase/ORM/EntityTest.php | 6 +++--- tests/TestCase/ORM/MarshallerTest.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/TestCase/ORM/EntityTest.php b/tests/TestCase/ORM/EntityTest.php index 05d767a1782..129730e7ee7 100644 --- a/tests/TestCase/ORM/EntityTest.php +++ b/tests/TestCase/ORM/EntityTest.php @@ -71,11 +71,11 @@ public function testSetMultiplePropertiesNoSetters() $this->assertEquals(1, $entity->getOriginal('id')); $entity->set(['foo', 'bar']); - $this->assertEquals('foo', $entity->{0}); - $this->assertEquals('bar', $entity->{1}); + $this->assertEquals('foo', $entity->get('0')); + $this->assertEquals('bar', $entity->get('1')); $entity->set(['sample']); - $this->assertEquals('sample', $entity->{0}); + $this->assertEquals('sample', $entity->get('0')); } /** diff --git a/tests/TestCase/ORM/MarshallerTest.php b/tests/TestCase/ORM/MarshallerTest.php index d78a83e2932..d5e4b53c881 100644 --- a/tests/TestCase/ORM/MarshallerTest.php +++ b/tests/TestCase/ORM/MarshallerTest.php @@ -147,8 +147,8 @@ public function testOneWithNumericField() ]; $marshall = new Marshaller($this->articles); $result = $marshall->one($data, []); - $this->assertEquals($data[0], $result->{0}); - $this->assertEquals($data[1], $result->{1}); + $this->assertEquals($data[0], $result->get('0')); + $this->assertEquals($data[1], $result->get('1')); } /** From 42c5a5baa49d73ce3b135c6003ba21dda4cc39ed Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 21 Jul 2020 22:41:17 +0530 Subject: [PATCH 15/18] Remove unneeded ignores --- psalm-baseline.xml | 14 ++------------ src/TestSuite/IntegrationTestTrait.php | 1 - 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index a4526967f40..0b9f63beb17 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + $iterator @@ -116,13 +116,8 @@ - + $this->_repository - $this->getRepository() - $this->getRepository() - $this->getRepository() - $this->getRepository() - $this->getRepository() @@ -152,11 +147,6 @@ new AssertionFailedError($message) - - - new AssertionFailedError('There is no stored session data. Perhaps you need to run a request?') - - FixtureInjector diff --git a/src/TestSuite/IntegrationTestTrait.php b/src/TestSuite/IntegrationTestTrait.php index 75f2176f0e7..5fefc2e1297 100644 --- a/src/TestSuite/IntegrationTestTrait.php +++ b/src/TestSuite/IntegrationTestTrait.php @@ -659,7 +659,6 @@ protected function _addTokens(string $url, array $data): array $formProtector = new FormProtector(['unlockedFields' => $this->_unlockedFields]); foreach ($keys as $field) { - /** @psalm-suppress PossiblyNullArgument */ $formProtector->addField($field); } $tokenData = $formProtector->buildTokenData($url, 'cli'); From f6966cd9eeef459bd3c153b30fd2fbf724869200 Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 21 Jul 2020 19:33:05 +0530 Subject: [PATCH 16/18] Update use of deprecated phpunit method. --- .../TestCase/Auth/ControllerAuthorizeTest.php | 2 +- tests/TestCase/Auth/FormAuthenticateTest.php | 2 +- tests/TestCase/Collection/CollectionTest.php | 22 ++-- .../Iterator/FilterIteratorTest.php | 2 +- .../Iterator/ReplaceIteratorTest.php | 2 +- .../Command/PluginAssetsCommandsTest.php | 4 +- .../Command/SchemaCacheCommandsTest.php | 4 +- tests/TestCase/Console/CommandRunnerTest.php | 28 ++--- tests/TestCase/Console/CommandTest.php | 6 +- tests/TestCase/Console/ConsoleOutputTest.php | 2 +- .../TestCase/Console/ShellDispatcherTest.php | 24 ++-- tests/TestCase/Console/ShellTest.php | 59 ++++++---- .../Component/AuthComponentTest.php | 41 ++++--- .../Component/PaginatorComponentTest.php | 7 +- .../Component/RequestHandlerComponentTest.php | 2 +- tests/TestCase/Controller/ControllerTest.php | 4 +- tests/TestCase/Database/ConnectionTest.php | 20 ++-- tests/TestCase/Database/Driver/MysqlTest.php | 12 +- .../TestCase/Database/Driver/PostgresTest.php | 20 ++-- tests/TestCase/Database/Driver/SqliteTest.php | 9 +- .../Database/Driver/SqlserverTest.php | 30 ++--- tests/TestCase/Database/DriverTest.php | 12 +- tests/TestCase/Database/QueryTest.php | 4 +- .../Database/Schema/MysqlSchemaTest.php | 3 +- .../Database/Schema/PostgresSchemaTest.php | 2 +- .../Database/Schema/SqliteSchemaTest.php | 6 +- .../Database/Schema/SqlserverSchemaTest.php | 2 +- .../TestCase/Database/Type/StringTypeTest.php | 2 +- tests/TestCase/Database/ValueBinderTest.php | 2 +- .../Datasource/PaginatorTestTrait.php | 5 +- .../Error/ConsoleErrorHandlerTest.php | 2 +- .../TestCase/Error/ExceptionRendererTest.php | 8 +- .../Middleware/ErrorHandlerMiddlewareTest.php | 4 +- tests/TestCase/Event/EventManagerTest.php | 8 +- tests/TestCase/Form/FormTest.php | 4 +- .../Http/Client/Adapter/StreamTest.php | 2 +- .../TestCase/Http/Client/Auth/DigestTest.php | 2 +- tests/TestCase/Http/ClientTest.php | 32 +++--- tests/TestCase/Http/ResponseEmitterTest.php | 2 +- tests/TestCase/Http/ServerTest.php | 3 +- tests/TestCase/Log/Engine/SyslogLogTest.php | 8 +- tests/TestCase/Mailer/MailerTest.php | 12 +- .../Mailer/Transport/MailTransportTest.php | 2 +- .../Mailer/Transport/SmtpTransportTest.php | 8 +- tests/TestCase/Network/SocketTest.php | 2 +- .../ORM/Association/BelongsToManyTest.php | 32 +++--- .../ORM/Association/BelongsToTest.php | 2 +- .../TestCase/ORM/Association/HasManyTest.php | 6 +- tests/TestCase/ORM/Association/HasOneTest.php | 6 +- .../ORM/AssociationCollectionTest.php | 22 ++-- tests/TestCase/ORM/AssociationProxyTest.php | 2 +- tests/TestCase/ORM/AssociationTest.php | 18 +-- tests/TestCase/ORM/BehaviorRegistryTest.php | 4 +- tests/TestCase/ORM/CompositeKeysTest.php | 2 +- tests/TestCase/ORM/EagerLoaderTest.php | 4 +- tests/TestCase/ORM/EntityTest.php | 56 ++++----- tests/TestCase/ORM/QueryTest.php | 10 +- .../TestCase/ORM/Rule/LinkConstraintTest.php | 2 +- tests/TestCase/ORM/TableTest.php | 107 +++++++++--------- .../Middleware/RoutingMiddlewareTest.php | 2 +- tests/TestCase/Routing/Route/RouteTest.php | 2 +- .../TestCase/Routing/RouteCollectionTest.php | 4 +- tests/TestCase/Routing/RouterTest.php | 2 +- .../TestCase/TestSuite/FixtureManagerTest.php | 12 +- tests/TestCase/TestSuite/TestFixtureTest.php | 2 +- tests/TestCase/TestSuite/TestSuiteTest.php | 8 +- tests/TestCase/Validation/ValidatorTest.php | 4 +- tests/TestCase/View/Helper/HtmlHelperTest.php | 2 +- .../TestCase/View/Helper/NumberHelperTest.php | 2 +- tests/TestCase/View/Helper/TextHelperTest.php | 8 +- 70 files changed, 392 insertions(+), 368 deletions(-) diff --git a/tests/TestCase/Auth/ControllerAuthorizeTest.php b/tests/TestCase/Auth/ControllerAuthorizeTest.php index 41056f72a74..543581964a7 100644 --- a/tests/TestCase/Auth/ControllerAuthorizeTest.php +++ b/tests/TestCase/Auth/ControllerAuthorizeTest.php @@ -43,7 +43,7 @@ public function setUp(): void { parent::setUp(); $this->controller = $this->getMockBuilder(Controller::class) - ->setMethods(['isAuthorized']) + ->addMethods(['isAuthorized']) ->disableOriginalConstructor() ->getMock(); $this->components = new ComponentRegistry($this->controller); diff --git a/tests/TestCase/Auth/FormAuthenticateTest.php b/tests/TestCase/Auth/FormAuthenticateTest.php index 89fb70c8f8a..a489262c4bd 100644 --- a/tests/TestCase/Auth/FormAuthenticateTest.php +++ b/tests/TestCase/Auth/FormAuthenticateTest.php @@ -162,7 +162,7 @@ public function testAuthenticatePasswordIsEmptyString(): void ]); $this->auth = $this->getMockBuilder(FormAuthenticate::class) - ->setMethods(['_checkFields']) + ->onlyMethods(['_checkFields']) ->setConstructorArgs([ $this->collection, ['userModel' => 'Users'], diff --git a/tests/TestCase/Collection/CollectionTest.php b/tests/TestCase/Collection/CollectionTest.php index 8b8d9829021..8f97e31d81e 100644 --- a/tests/TestCase/Collection/CollectionTest.php +++ b/tests/TestCase/Collection/CollectionTest.php @@ -219,7 +219,7 @@ public function testEach() $items = ['a' => 1, 'b' => 2, 'c' => 3]; $collection = new Collection($items); $callable = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) + ->addMethods(['__invoke']) ->getMock(); $callable->expects($this->at(0)) ->method('__invoke') @@ -267,7 +267,7 @@ public function testFilterChaining() $items = ['a' => 1, 'b' => 2, 'c' => 3]; $collection = new Collection($items); $callable = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) + ->addMethods(['__invoke']) ->getMock(); $callable->expects($this->once()) @@ -315,7 +315,7 @@ public function testEveryReturnTrue() $items = ['a' => 1, 'b' => 2, 'c' => 3]; $collection = new Collection($items); $callable = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) + ->addMethods(['__invoke']) ->getMock(); $callable->expects($this->at(0)) @@ -343,7 +343,7 @@ public function testEveryReturnFalse() $items = ['a' => 1, 'b' => 2, 'c' => 3]; $collection = new Collection($items); $callable = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) + ->addMethods(['__invoke']) ->getMock(); $callable->expects($this->at(0)) @@ -360,7 +360,7 @@ public function testEveryReturnFalse() $items = []; $collection = new Collection($items); $callable = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) + ->addMethods(['__invoke']) ->getMock(); $callable->expects($this->never()) @@ -384,7 +384,7 @@ public function testSomeReturnTrue() $items = ['a' => 1, 'b' => 2, 'c' => 3]; $collection = new Collection($items); $callable = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) + ->addMethods(['__invoke']) ->getMock(); $callable->expects($this->at(0)) @@ -409,7 +409,7 @@ public function testSomeReturnFalse() $items = ['a' => 1, 'b' => 2, 'c' => 3]; $collection = new Collection($items); $callable = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) + ->addMethods(['__invoke']) ->getMock(); $callable->expects($this->at(0)) @@ -488,7 +488,7 @@ public function testReduceWithInitialValue($items) { $collection = new Collection($items); $callable = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) + ->addMethods(['__invoke']) ->getMock(); $callable->expects($this->at(0)) @@ -520,7 +520,7 @@ public function testReduceWithoutInitialValue($items) { $collection = new Collection($items); $callable = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) + ->addMethods(['__invoke']) ->getMock(); $callable->expects($this->at(0)) @@ -1244,7 +1244,7 @@ public function testCompile() $items = ['a' => 1, 'b' => 2, 'c' => 3]; $collection = new Collection($items); $callable = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) + ->addMethods(['__invoke']) ->getMock(); $callable->expects($this->at(0)) @@ -2781,7 +2781,7 @@ public function testLazy() $items = ['a' => 1, 'b' => 2, 'c' => 3]; $collection = (new Collection($items))->lazy(); $callable = $this->getMockBuilder(stdClass::class) - ->setMethods(['__invoke']) + ->addMethods(['__invoke']) ->getMock(); $callable->expects($this->never())->method('__invoke'); diff --git a/tests/TestCase/Collection/Iterator/FilterIteratorTest.php b/tests/TestCase/Collection/Iterator/FilterIteratorTest.php index 9ff30c71f5b..dd95b32c613 100644 --- a/tests/TestCase/Collection/Iterator/FilterIteratorTest.php +++ b/tests/TestCase/Collection/Iterator/FilterIteratorTest.php @@ -33,7 +33,7 @@ public function testFilter() { $items = new \ArrayIterator([1, 2, 3]); $callable = $this->getMockBuilder(\stdClass::class) - ->setMethods(['__invoke']) + ->addMethods(['__invoke']) ->getMock(); $callable->expects($this->at(0)) ->method('__invoke') diff --git a/tests/TestCase/Collection/Iterator/ReplaceIteratorTest.php b/tests/TestCase/Collection/Iterator/ReplaceIteratorTest.php index 7996c5a07bf..a9842431f97 100644 --- a/tests/TestCase/Collection/Iterator/ReplaceIteratorTest.php +++ b/tests/TestCase/Collection/Iterator/ReplaceIteratorTest.php @@ -33,7 +33,7 @@ public function testReplace() { $items = new \ArrayIterator([1, 2, 3]); $callable = $this->getMockBuilder(\stdClass::class) - ->setMethods(['__invoke']) + ->addMethods(['__invoke']) ->getMock(); $callable->expects($this->at(0)) ->method('__invoke') diff --git a/tests/TestCase/Command/PluginAssetsCommandsTest.php b/tests/TestCase/Command/PluginAssetsCommandsTest.php index abf29cb79b9..02121ffce71 100644 --- a/tests/TestCase/Command/PluginAssetsCommandsTest.php +++ b/tests/TestCase/Command/PluginAssetsCommandsTest.php @@ -140,14 +140,14 @@ public function testSymlinkWhenTargetAlreadyExits() $output = new ConsoleOutput(); $io = $this->getMockBuilder(ConsoleIo::class) ->setConstructorArgs([$output, $output, null, null]) - ->setMethods(['in']) + ->addMethods(['in']) ->getMock(); $parser = new ConsoleOptionParser('cake example'); $parser->addArgument('name', ['optional' => true]); $parser->addOption('overwrite', ['default' => false, 'boolean' => true]); $command = $this->getMockBuilder('Cake\Command\PluginAssetsSymlinkCommand') - ->setMethods(['getOptionParser', '_createSymlink', '_copyDirectory']) + ->onlyMethods(['getOptionParser', '_createSymlink', '_copyDirectory']) ->getMock(); $command->method('getOptionParser')->will($this->returnValue($parser)); diff --git a/tests/TestCase/Command/SchemaCacheCommandsTest.php b/tests/TestCase/Command/SchemaCacheCommandsTest.php index ef2f3cb5c61..5c3c36d6ca9 100644 --- a/tests/TestCase/Command/SchemaCacheCommandsTest.php +++ b/tests/TestCase/Command/SchemaCacheCommandsTest.php @@ -60,7 +60,7 @@ public function setUp(): void $this->useCommandRunner(); $this->cache = $this->getMockBuilder(NullEngine::class) - ->setMethods(['set', 'get', 'delete']) + ->onlyMethods(['set', 'get', 'delete']) ->getMock(); Cache::setConfig('orm_cache', $this->cache); @@ -87,7 +87,7 @@ protected function getShell() $io = $this->getMockBuilder(ConsoleIo::class)->getMock(); $shell = $this->getMockBuilder(SchemaCacheShell::class) ->setConstructorArgs([$io]) - ->setMethods(['_getSchemaCache']) + ->onlyMethods(['_getSchemaCache']) ->getMock(); $schemaCache = new SchemaCache($this->connection); diff --git a/tests/TestCase/Console/CommandRunnerTest.php b/tests/TestCase/Console/CommandRunnerTest.php index 7840fc80429..960f39425e2 100644 --- a/tests/TestCase/Console/CommandRunnerTest.php +++ b/tests/TestCase/Console/CommandRunnerTest.php @@ -116,7 +116,7 @@ public function testRunMissingRootCommand() $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Cannot run any commands. No arguments received.'); $app = $this->getMockBuilder(BaseApplication::class) - ->setMethods(['middleware', 'bootstrap', 'routes']) + ->onlyMethods(['middleware', 'bootstrap', 'routes']) ->setConstructorArgs([$this->config]) ->getMock(); @@ -132,7 +132,7 @@ public function testRunMissingRootCommand() public function testRunInvalidCommand() { $app = $this->getMockBuilder(BaseApplication::class) - ->setMethods(['middleware', 'bootstrap', 'routes']) + ->onlyMethods(['middleware', 'bootstrap', 'routes']) ->setConstructorArgs([$this->config]) ->getMock(); @@ -155,7 +155,7 @@ public function testRunInvalidCommand() public function testRunInvalidCommandSuggestion() { $app = $this->getMockBuilder(BaseApplication::class) - ->setMethods(['middleware', 'bootstrap', 'routes']) + ->onlyMethods(['middleware', 'bootstrap', 'routes']) ->setConstructorArgs([$this->config]) ->getMock(); @@ -182,7 +182,7 @@ public function testRunInvalidCommandSuggestion() public function testRunHelpLongOption() { $app = $this->getMockBuilder(BaseApplication::class) - ->setMethods(['middleware', 'bootstrap', 'routes']) + ->onlyMethods(['middleware', 'bootstrap', 'routes']) ->setConstructorArgs([$this->config]) ->getMock(); @@ -204,7 +204,7 @@ public function testRunHelpLongOption() public function testRunHelpShortOption() { $app = $this->getMockBuilder(BaseApplication::class) - ->setMethods(['middleware', 'bootstrap', 'routes']) + ->onlyMethods(['middleware', 'bootstrap', 'routes']) ->setConstructorArgs([$this->config]) ->getMock(); @@ -225,7 +225,7 @@ public function testRunHelpShortOption() public function testRunNoCommand() { $app = $this->getMockBuilder(BaseApplication::class) - ->setMethods(['middleware', 'bootstrap', 'routes']) + ->onlyMethods(['middleware', 'bootstrap', 'routes']) ->setConstructorArgs([$this->config]) ->getMock(); @@ -248,7 +248,7 @@ public function testRunNoCommand() public function testRunVersionAlias() { $app = $this->getMockBuilder(BaseApplication::class) - ->setMethods(['middleware', 'bootstrap', 'routes']) + ->onlyMethods(['middleware', 'bootstrap', 'routes']) ->setConstructorArgs([$this->config]) ->getMock(); @@ -266,7 +266,7 @@ public function testRunVersionAlias() public function testRunValidCommand() { $app = $this->getMockBuilder(BaseApplication::class) - ->setMethods(['middleware', 'bootstrap', 'routes']) + ->onlyMethods(['middleware', 'bootstrap', 'routes']) ->setConstructorArgs([$this->config]) ->getMock(); @@ -289,7 +289,7 @@ public function testRunValidCommand() public function testRunValidCommandInflection() { $app = $this->getMockBuilder(BaseApplication::class) - ->setMethods(['middleware', 'bootstrap', 'routes']) + ->onlyMethods(['middleware', 'bootstrap', 'routes']) ->setConstructorArgs([$this->config]) ->getMock(); @@ -462,7 +462,7 @@ public function testRunValidCommandClassHelp() public function testRunTriggersBuildCommandsEvent() { $app = $this->getMockBuilder(BaseApplication::class) - ->setMethods(['middleware', 'bootstrap', 'routes']) + ->onlyMethods(['middleware', 'bootstrap', 'routes']) ->setConstructorArgs([$this->config]) ->getMock(); @@ -484,7 +484,7 @@ public function testRunTriggersBuildCommandsEvent() public function testRunCallsPluginHookMethods() { $app = $this->getMockBuilder(BaseApplication::class) - ->setMethods([ + ->onlyMethods([ 'middleware', 'bootstrap', 'routes', 'pluginBootstrap', 'pluginConsole', 'pluginRoutes', ]) @@ -518,7 +518,7 @@ public function testRunCallsPluginHookMethods() public function testRunLoadsRoutes() { $app = $this->getMockBuilder(BaseApplication::class) - ->setMethods(['middleware', 'bootstrap']) + ->onlyMethods(['middleware', 'bootstrap']) ->setConstructorArgs([TEST_APP . 'config' . DS]) ->getMock(); @@ -531,7 +531,7 @@ public function testRunLoadsRoutes() protected function makeAppWithCommands($commands) { $app = $this->getMockBuilder(BaseApplication::class) - ->setMethods(['middleware', 'bootstrap', 'console', 'routes']) + ->onlyMethods(['middleware', 'bootstrap', 'console', 'routes']) ->setConstructorArgs([$this->config]) ->getMock(); $collection = new CommandCollection($commands); @@ -544,7 +544,7 @@ protected function getMockIo($output) { $io = $this->getMockBuilder(ConsoleIo::class) ->setConstructorArgs([$output, $output, null, null]) - ->setMethods(['in']) + ->addMethods(['in']) ->getMock(); return $io; diff --git a/tests/TestCase/Console/CommandTest.php b/tests/TestCase/Console/CommandTest.php index cc2a4eaab13..5978a2eb3a4 100644 --- a/tests/TestCase/Console/CommandTest.php +++ b/tests/TestCase/Console/CommandTest.php @@ -133,7 +133,7 @@ public function testRunCallsInitialize() { /** @var \Cake\Console\Command|\PHPUnit\Framework\MockObject\MockObject $command */ $command = $this->getMockBuilder(Command::class) - ->setMethods(['initialize']) + ->onlyMethods(['initialize']) ->getMock(); $command->setName('cake example'); $command->expects($this->once())->method('initialize'); @@ -226,7 +226,7 @@ public function testRunOptionParserFailure() { /** @var \Cake\Console\Command|\PHPUnit\Framework\MockObject\MockObject $command */ $command = $this->getMockBuilder(Command::class) - ->setMethods(['getOptionParser']) + ->onlyMethods(['getOptionParser']) ->getMock(); $parser = new ConsoleOptionParser('cake example'); $parser->addArgument('name', ['required' => true]); @@ -389,7 +389,7 @@ protected function getMockIo($output) { $io = $this->getMockBuilder(ConsoleIo::class) ->setConstructorArgs([$output, $output, null, null]) - ->setMethods(['in']) + ->addMethods(['in']) ->getMock(); return $io; diff --git a/tests/TestCase/Console/ConsoleOutputTest.php b/tests/TestCase/Console/ConsoleOutputTest.php index aeb0f1d2162..221e0065777 100644 --- a/tests/TestCase/Console/ConsoleOutputTest.php +++ b/tests/TestCase/Console/ConsoleOutputTest.php @@ -40,7 +40,7 @@ public function setUp(): void { parent::setUp(); $this->output = $this->getMockBuilder(ConsoleOutput::class) - ->setMethods(['_write']) + ->onlyMethods(['_write']) ->getMock(); $this->output->setOutputAs(ConsoleOutput::COLOR); } diff --git a/tests/TestCase/Console/ShellDispatcherTest.php b/tests/TestCase/Console/ShellDispatcherTest.php index 5b5c9f8ddce..24c8a431605 100644 --- a/tests/TestCase/Console/ShellDispatcherTest.php +++ b/tests/TestCase/Console/ShellDispatcherTest.php @@ -37,7 +37,7 @@ public function setUp(): void $this->loadPlugins(['TestPlugin', 'Company/TestPluginThree']); static::setAppNamespace(); $this->dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher') - ->setMethods(['_stop']) + ->addMethods(['_stop']) ->getMock(); } @@ -161,7 +161,7 @@ public function testDispatchShellWithAbort() { $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock(); $shell = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['main']) + ->addMethods(['main']) ->setConstructorArgs([$io]) ->getMock(); $shell->expects($this->once()) @@ -171,7 +171,7 @@ public function testDispatchShellWithAbort() })); $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher') - ->setMethods(['findShell']) + ->onlyMethods(['findShell']) ->getMock(); $dispatcher->expects($this->any()) ->method('findShell') @@ -191,7 +191,7 @@ public function testDispatchShellWithAbort() public function testDispatchShellWithMain() { $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher') - ->setMethods(['findShell']) + ->onlyMethods(['findShell']) ->getMock(); $Shell = $this->getMockBuilder('Cake\Console\Shell') ->disableOriginalConstructor() @@ -227,7 +227,7 @@ public function testDispatchShellWithMain() public function testDispatchShellWithIntegerSuccessCode() { $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher') - ->setMethods(['findShell']) + ->onlyMethods(['findShell']) ->getMock(); $Shell = $this->getMockBuilder('Cake\Console\Shell') ->disableOriginalConstructor() @@ -258,7 +258,7 @@ public function testDispatchShellWithCustomIntegerCodes() $customErrorCode = 3; $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher') - ->setMethods(['findShell']) + ->onlyMethods(['findShell']) ->getMock(); $Shell = $this->getMockBuilder('Cake\Console\Shell') ->disableOriginalConstructor() @@ -287,7 +287,7 @@ public function testDispatchShellWithCustomIntegerCodes() public function testDispatchShellWithoutMain() { $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher') - ->setMethods(['findShell']) + ->onlyMethods(['findShell']) ->getMock(); $Shell = $this->getMockBuilder('Cake\Console\Shell') ->disableOriginalConstructor() @@ -316,7 +316,7 @@ public function testDispatchShellWithoutMain() public function testDispatchShortPluginAlias() { $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher') - ->setMethods(['_shellExists', '_createShell']) + ->onlyMethods(['_shellExists', '_createShell']) ->getMock(); $Shell = $this->getMockBuilder('Cake\Console\Shell') ->disableOriginalConstructor() @@ -345,7 +345,7 @@ public function testDispatchShortPluginAlias() public function testDispatchShortPluginAliasCamelized() { $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher') - ->setMethods(['_shellExists', '_createShell']) + ->onlyMethods(['_shellExists', '_createShell']) ->getMock(); $Shell = $this->getMockBuilder('Cake\Console\Shell') ->disableOriginalConstructor() @@ -374,7 +374,7 @@ public function testDispatchShortPluginAliasCamelized() public function testDispatchShortPluginAliasConflict() { $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher') - ->setMethods(['_shellExists', '_createShell']) + ->onlyMethods(['_shellExists', '_createShell']) ->getMock(); $Shell = $this->getMockBuilder('Cake\Console\Shell') ->disableOriginalConstructor() @@ -432,7 +432,7 @@ public function testHelpOption() { $this->expectException(Warning::class); $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher') - ->setMethods(['_stop']) + ->addMethods(['_stop']) ->getMock(); $dispatcher->args = ['--help']; $dispatcher->dispatch(); @@ -447,7 +447,7 @@ public function testVersionOption() { $this->expectException(Warning::class); $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher') - ->setMethods(['_stop']) + ->addMethods(['_stop']) ->getMock(); $dispatcher->args = ['--version']; $dispatcher->dispatch(); diff --git a/tests/TestCase/Console/ShellTest.php b/tests/TestCase/Console/ShellTest.php index 022485c3fe8..9101a683ea1 100644 --- a/tests/TestCase/Console/ShellTest.php +++ b/tests/TestCase/Console/ShellTest.php @@ -719,7 +719,8 @@ public function testRunCommandMain() $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock(); /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */ $shell = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['main', 'startup']) + ->onlyMethods(['startup']) + ->addMethods(['main']) ->setConstructorArgs([$io]) ->getMock(); @@ -742,7 +743,8 @@ public function testRunCommandWithMethod() $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock(); /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */ $shell = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['hitMe', 'startup']) + ->onlyMethods(['startup']) + ->addMethods(['hitMe']) ->setConstructorArgs([$io]) ->getMock(); @@ -766,12 +768,13 @@ public function testRunCommandWithMethod() public function testRunCommandWithExtra() { $Parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser') - ->setMethods(['help']) + ->onlyMethods(['help']) ->setConstructorArgs(['knife']) ->getMock(); $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock(); $Shell = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['getOptionParser', 'slice', '_welcome', 'param']) + ->onlyMethods(['getOptionParser', '_welcome', 'param']) + ->addMethods(['slice']) ->setConstructorArgs([$io]) ->getMock(); $Parser->addSubCommand('slice'); @@ -916,7 +919,8 @@ public function testRunCommandAutoMethodOff() $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock(); /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */ $shell = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['hit_me', 'startup']) + ->onlyMethods(['startup']) + ->addMethods(['hit_me']) ->setConstructorArgs([$io]) ->getMock(); @@ -938,12 +942,13 @@ public function testRunCommandAutoMethodOff() public function testRunCommandWithMethodNotInSubcommands() { $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser') - ->setMethods(['help']) + ->onlyMethods(['help']) ->setConstructorArgs(['knife']) ->getMock(); $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock(); $shell = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['getOptionParser', 'roll', 'startup']) + ->onlyMethods(['getOptionParser', 'startup']) + ->addMethods(['roll']) ->setConstructorArgs([$io]) ->getMock(); @@ -971,12 +976,13 @@ public function testRunCommandWithMethodNotInSubcommands() public function testRunCommandWithMethodInSubcommands() { $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser') - ->setMethods(['help']) + ->onlyMethods(['help']) ->setConstructorArgs(['knife']) ->getMock(); $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock(); $shell = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['getOptionParser', 'slice', 'startup']) + ->onlyMethods(['getOptionParser', 'startup']) + ->addMethods(['slice']) ->setConstructorArgs([$io]) ->getMock(); @@ -1003,7 +1009,7 @@ public function testRunCommandWithMissingMethodInSubcommands() { /** @var \Cake\Console\ConsoleOptionParser|\PHPUnit\Framework\MockObject\MockObject $parser */ $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser') - ->setMethods(['help']) + ->onlyMethods(['help']) ->setConstructorArgs(['knife']) ->getMock(); $parser->addSubCommand('slice'); @@ -1011,7 +1017,7 @@ public function testRunCommandWithMissingMethodInSubcommands() $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock(); /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */ $shell = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['getOptionParser', 'startup']) + ->onlyMethods(['getOptionParser', 'startup']) ->setConstructorArgs([$io]) ->getMock(); $shell->expects($this->any()) @@ -1036,12 +1042,12 @@ public function testRunCommandBaseClassMethod() { /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */ $shell = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['startup', 'getOptionParser', 'hr']) + ->onlyMethods(['startup', 'getOptionParser', 'hr']) ->disableOriginalConstructor() ->getMock(); $shell->setIo( $this->getMockBuilder('Cake\Console\ConsoleIo') - ->setMethods(['err']) + ->onlyMethods(['err']) ->getMock() ); $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser') @@ -1068,12 +1074,12 @@ public function testRunCommandMissingMethod() { /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */ $shell = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['startup', 'getOptionParser', 'hr']) + ->onlyMethods(['startup', 'getOptionParser', 'hr']) ->disableOriginalConstructor() ->getMock(); $shell->setIo( $this->getMockBuilder('Cake\Console\ConsoleIo') - ->setMethods(['err']) + ->onlyMethods(['err']) ->getMock() ); $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser') @@ -1107,7 +1113,7 @@ public function testRunCommandTriggeringHelp() $parser->expects($this->once())->method('help'); $shell = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['getOptionParser', 'out', 'startup', '_welcome']) + ->onlyMethods(['getOptionParser', 'out', 'startup', '_welcome']) ->disableOriginalConstructor() ->getMock(); $shell->setIo($this->getMockBuilder('Cake\Console\ConsoleIo')->getMock()); @@ -1127,16 +1133,16 @@ public function testRunCommandNotCallUnexposedTask() { /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */ $shell = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['startup', 'hasTask']) + ->onlyMethods(['startup', 'hasTask']) ->disableOriginalConstructor() ->getMock(); $shell->setIo( $this->getMockBuilder('Cake\Console\ConsoleIo') - ->setMethods(['err']) + ->onlyMethods(['err']) ->getMock() ); $task = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['runCommand']) + ->onlyMethods(['runCommand']) ->disableOriginalConstructor() ->getMock(); @@ -1166,12 +1172,13 @@ public function testRunCommandHittingTaskInSubcommand() $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock(); $shell = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['hasTask', 'startup', 'getOptionParser']) + ->onlyMethods(['hasTask', 'startup', 'getOptionParser']) ->disableOriginalConstructor() ->getMock(); $shell->setIo($io); $task = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['main', 'runCommand']) + ->onlyMethods(['runCommand']) + ->addMethods(['main']) ->disableOriginalConstructor() ->getMock(); $task->setIo($io); @@ -1203,11 +1210,12 @@ public function testRunCommandInvokeTask() $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock(); $shell = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['hasTask', 'getOptionParser']) + ->onlyMethods(['hasTask', 'getOptionParser']) ->setConstructorArgs([$io]) ->getMock(); $task = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['main', '_welcome']) + ->onlyMethods(['_welcome']) + ->addMethods(['main']) ->setConstructorArgs([$io]) ->getMock(); @@ -1236,7 +1244,8 @@ public function testRunCommandMainMissingArgument() { $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock(); $shell = $this->getMockBuilder('Cake\Console\Shell') - ->setMethods(['main', 'startup', 'getOptionParser']) + ->onlyMethods(['startup', 'getOptionParser']) + ->addMethods(['main']) ->setConstructorArgs([$io]) ->getMock(); @@ -1377,7 +1386,7 @@ public function testQuietLog() ->with(ConsoleIo::QUIET); $this->Shell = $this->getMockBuilder(ShellTestShell::class) - ->setMethods(['welcome']) + ->addMethods(['welcome']) ->setConstructorArgs([$io]) ->getMock(); $this->Shell->runCommand(['foo', '--quiet']); diff --git a/tests/TestCase/Controller/Component/AuthComponentTest.php b/tests/TestCase/Controller/Component/AuthComponentTest.php index b7e61047915..d5a71ff7e7a 100644 --- a/tests/TestCase/Controller/Component/AuthComponentTest.php +++ b/tests/TestCase/Controller/Component/AuthComponentTest.php @@ -128,7 +128,7 @@ public function testNoAuth(): void public function testIdentify(): void { $AuthLoginFormAuthenticate = $this->getMockBuilder(FormAuthenticate::class) - ->setMethods(['authenticate']) + ->onlyMethods(['authenticate']) ->disableOriginalConstructor() ->getMock(); $this->Auth->authenticate = [ @@ -169,7 +169,7 @@ public function testIdentify(): void public function testIdentifyArrayAccess(): void { $AuthLoginFormAuthenticate = $this->getMockBuilder(FormAuthenticate::class) - ->setMethods(['authenticate']) + ->onlyMethods(['authenticate']) ->disableOriginalConstructor() ->getMock(); $this->Auth->authenticate = [ @@ -251,15 +251,15 @@ public function testIsAuthorizedMissingFile(): void public function testIsAuthorizedDelegation(): void { $AuthMockOneAuthorize = $this->getMockBuilder(BaseAuthorize::class) - ->setMethods(['authorize']) + ->onlyMethods(['authorize']) ->disableOriginalConstructor() ->getMock(); $AuthMockTwoAuthorize = $this->getMockBuilder(BaseAuthorize::class) - ->setMethods(['authorize']) + ->onlyMethods(['authorize']) ->disableOriginalConstructor() ->getMock(); $AuthMockThreeAuthorize = $this->getMockBuilder(BaseAuthorize::class) - ->setMethods(['authorize']) + ->onlyMethods(['authorize']) ->disableOriginalConstructor() ->getMock(); @@ -293,7 +293,7 @@ public function testIsAuthorizedDelegation(): void public function testIsAuthorizedWithArrayObject(): void { $AuthMockOneAuthorize = $this->getMockBuilder(BaseAuthorize::class) - ->setMethods(['authorize']) + ->onlyMethods(['authorize']) ->disableOriginalConstructor() ->getMock(); @@ -319,7 +319,7 @@ public function testIsAuthorizedWithArrayObject(): void public function testIsAuthorizedUsingUserInSession(): void { $AuthMockFourAuthorize = $this->getMockBuilder(BaseAuthorize::class) - ->setMethods(['authorize']) + ->onlyMethods(['authorize']) ->disableOriginalConstructor() ->getMock(); $this->Auth->setConfig('authorize', ['AuthMockFour']); @@ -823,7 +823,7 @@ public function testNoLoginRedirectForAuthenticatedUser(): void $this->Auth->getController()->getRequest()->getSession()->write('Auth.User.id', '1'); $this->Auth->setConfig('authenticate', ['Form']); $this->getMockBuilder(BaseAuthorize::class) - ->setMethods(['authorize']) + ->onlyMethods(['authorize']) ->disableOriginalConstructor() ->setMockClassName('NoLoginRedirectMockAuthorize') ->getMock(); @@ -900,7 +900,8 @@ public function testDefaultToLoginRedirect(): void $response = new Response(); $Controller = $this->getMockBuilder('Cake\Controller\Controller') - ->setMethods(['on', 'redirect']) + ->onlyMethods(['redirect']) + ->addMethods(['on']) ->setConstructorArgs([$request, $response]) ->getMock(); $event = new Event('Controller.startup', $Controller); @@ -923,7 +924,7 @@ public function testRedirectToUnauthorizedRedirect(): void { $url = '/party/on'; $this->Auth->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') - ->setMethods(['set']) + ->onlyMethods(['set']) ->setConstructorArgs([$this->Controller->components()]) ->getMock(); $request = new ServerRequest([ @@ -939,7 +940,8 @@ public function testRedirectToUnauthorizedRedirect(): void $response = new Response(); $controller = $this->getMockBuilder('Cake\Controller\Controller') - ->setMethods(['on', 'redirect']) + ->onlyMethods(['redirect']) + ->addMethods(['on']) ->setConstructorArgs([$request, $response]) ->getMock(); @@ -964,7 +966,7 @@ public function testRedirectToUnauthorizedRedirectLoginAction(): void { $url = '/party/on'; $this->Auth->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') - ->setMethods(['set']) + ->onlyMethods(['set']) ->setConstructorArgs([$this->Controller->components()]) ->getMock(); $request = new ServerRequest([ @@ -980,7 +982,8 @@ public function testRedirectToUnauthorizedRedirectLoginAction(): void $response = new Response(); $controller = $this->getMockBuilder('Cake\Controller\Controller') - ->setMethods(['on', 'redirect']) + ->onlyMethods(['redirect']) + ->addMethods(['on']) ->setConstructorArgs([$request, $response]) ->getMock(); @@ -1003,7 +1006,7 @@ public function testRedirectToUnauthorizedRedirectSuppressedAuthError(): void { $url = '/party/on'; $session = $this->getMockBuilder(Session::class) - ->setMethods(['flash']) + ->addMethods(['flash']) ->getMock(); $request = new ServerRequest([ 'session' => $session, @@ -1018,7 +1021,8 @@ public function testRedirectToUnauthorizedRedirectSuppressedAuthError(): void $response = new Response(); $controller = $this->getMockBuilder('Cake\Controller\Controller') - ->setMethods(['on', 'redirect']) + ->onlyMethods(['redirect']) + ->addMethods(['on']) ->setConstructorArgs([$request, $response]) ->getMock(); @@ -1053,7 +1057,8 @@ public function testForbiddenException(): void ->withRequestTarget('/party/on'); $response = new Response(); $Controller = $this->getMockBuilder('Cake\Controller\Controller') - ->setMethods(['on', 'redirect']) + ->onlyMethods(['redirect']) + ->addMethods(['on']) ->setConstructorArgs([$request, $response]) ->getMock(); @@ -1071,7 +1076,7 @@ public function testNoRedirectOnLoginAction(): void { $event = new Event('Controller.startup', $this->Controller); $controller = $this->getMockBuilder('Cake\Controller\Controller') - ->setMethods(['redirect']) + ->onlyMethods(['redirect']) ->getMock(); $controller->methods = ['login']; @@ -1375,7 +1380,7 @@ public function testAfterIdentifyForStatelessAuthentication(): void public function testSetUser(): void { $storage = $this->getMockBuilder('Cake\Auth\Storage\SessionStorage') - ->setMethods(['write']) + ->onlyMethods(['write']) ->setConstructorArgs([$this->Controller->getRequest(), $this->Controller->getResponse()]) ->getMock(); $this->Auth->storage($storage); diff --git a/tests/TestCase/Controller/Component/PaginatorComponentTest.php b/tests/TestCase/Controller/Component/PaginatorComponentTest.php index 9233aeba382..a0d06d5bc4d 100644 --- a/tests/TestCase/Controller/Component/PaginatorComponentTest.php +++ b/tests/TestCase/Controller/Component/PaginatorComponentTest.php @@ -1408,7 +1408,7 @@ public function testPaginateQueryWithLimit(): void protected function _getMockPosts(array $methods = []) { return $this->getMockBuilder('TestApp\Model\Table\PaginatorPostsTable') - ->setMethods($methods) + ->onlyMethods($methods) ->setConstructorArgs([[ 'connection' => ConnectionManager::get('test'), 'alias' => 'PaginatorPosts', @@ -1434,7 +1434,8 @@ protected function _getMockFindQuery(?RepositoryInterface $table = null) { /** @var \Cake\ORM\Query|\PHPUnit\Framework\MockObject\MockObject $query */ $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['total', 'all', 'count', 'applyOptions']) + ->onlyMethods(['all', 'count', 'applyOptions']) + ->addMethods(['total']) ->disableOriginalConstructor() ->getMock(); @@ -1466,7 +1467,7 @@ protected function _getMockFindQuery(?RepositoryInterface $table = null) protected function getMockRepository() { $model = $this->getMockBuilder(RepositoryInterface::class) - ->setMethods([ + ->onlyMethods([ 'getAlias', 'setAlias', 'setRegistryAlias', 'getRegistryAlias', 'hasField', 'find', 'get', 'query', 'updateAll', 'deleteAll', 'newEmptyEntity', 'exists', 'save', 'delete', 'newEntity', 'newEntities', 'patchEntity', 'patchEntities', diff --git a/tests/TestCase/Controller/Component/RequestHandlerComponentTest.php b/tests/TestCase/Controller/Component/RequestHandlerComponentTest.php index c89e78e28df..79e828ed53d 100644 --- a/tests/TestCase/Controller/Component/RequestHandlerComponentTest.php +++ b/tests/TestCase/Controller/Component/RequestHandlerComponentTest.php @@ -117,7 +117,7 @@ public function testConstructorConfig(): void ]; /** @var \Cake\Controller\Controller|\PHPUnit\Framework\MockObject\MockObject $controller */ $controller = $this->getMockBuilder(Controller::class) - ->setMethods(['redirect']) + ->onlyMethods(['redirect']) ->getMock(); $collection = new ComponentRegistry($controller); $requestHandler = new RequestHandlerComponent($collection, $config); diff --git a/tests/TestCase/Controller/ControllerTest.php b/tests/TestCase/Controller/ControllerTest.php index f8e8fefb400..fe689ed9211 100644 --- a/tests/TestCase/Controller/ControllerTest.php +++ b/tests/TestCase/Controller/ControllerTest.php @@ -427,7 +427,7 @@ public function testReferer(): void $this->assertSame('/posts/index', $result); $request = $this->getMockBuilder('Cake\Http\ServerRequest') - ->setMethods(['referer']) + ->onlyMethods(['referer']) ->getMock(); $request = new ServerRequest([ @@ -886,7 +886,7 @@ public function testComponentsWithCustomRegistry(): void $request = new ServerRequest(['url' => '/']); $response = new Response(); $componentRegistry = $this->getMockBuilder('Cake\Controller\ComponentRegistry') - ->setMethods(['offsetGet']) + ->addMethods(['offsetGet']) ->getMock(); $controller = new TestController($request, $response, null, null, $componentRegistry); diff --git a/tests/TestCase/Database/ConnectionTest.php b/tests/TestCase/Database/ConnectionTest.php index e58ff2694fb..d9986940446 100644 --- a/tests/TestCase/Database/ConnectionTest.php +++ b/tests/TestCase/Database/ConnectionTest.php @@ -176,7 +176,7 @@ public function testDisabledDriver() $this->expectException(\Cake\Database\Exception\MissingExtensionException::class); $this->expectExceptionMessage('Database driver DriverMock cannot be used due to a missing PHP extension or unmet dependency'); $mock = $this->getMockBuilder(Mysql::class) - ->setMethods(['enabled']) + ->onlyMethods(['enabled']) ->setMockClassName('DriverMock') ->getMock(); $connection = new Connection(['driver' => $mock]); @@ -818,7 +818,7 @@ public function testQuote() public function testQuoteIdentifier() { $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlite') - ->setMethods(['enabled']) + ->onlyMethods(['enabled']) ->getMock(); $driver->expects($this->once()) ->method('enabled') @@ -1033,7 +1033,7 @@ public function testLogBeginRollbackTransaction() $connection = $this ->getMockBuilder(Connection::class) - ->setMethods(['connect']) + ->onlyMethods(['connect']) ->disableOriginalConstructor() ->getMock(); $connection->enableQueryLogging(true); @@ -1060,7 +1060,7 @@ public function testLogCommitTransaction() { $driver = $this->getMockFormDriver(); $connection = $this->getMockBuilder(Connection::class) - ->setMethods(['connect']) + ->onlyMethods(['connect']) ->setConstructorArgs([['driver' => $driver]]) ->getMock(); @@ -1097,7 +1097,7 @@ public function testTransactionalSuccess() { $driver = $this->getMockFormDriver(); $connection = $this->getMockBuilder(Connection::class) - ->setMethods(['connect', 'commit', 'begin']) + ->onlyMethods(['connect', 'commit', 'begin']) ->setConstructorArgs([['driver' => $driver]]) ->getMock(); $connection->expects($this->at(0))->method('begin'); @@ -1120,7 +1120,7 @@ public function testTransactionalFail() { $driver = $this->getMockFormDriver(); $connection = $this->getMockBuilder(Connection::class) - ->setMethods(['connect', 'commit', 'begin', 'rollback']) + ->onlyMethods(['connect', 'commit', 'begin', 'rollback']) ->setConstructorArgs([['driver' => $driver]]) ->getMock(); $connection->expects($this->at(0))->method('begin'); @@ -1146,7 +1146,7 @@ public function testTransactionalWithException() $this->expectException(\InvalidArgumentException::class); $driver = $this->getMockFormDriver(); $connection = $this->getMockBuilder(Connection::class) - ->setMethods(['connect', 'commit', 'begin', 'rollback']) + ->onlyMethods(['connect', 'commit', 'begin', 'rollback']) ->setConstructorArgs([['driver' => $driver]]) ->getMock(); $connection->expects($this->at(0))->method('begin'); @@ -1167,7 +1167,7 @@ public function testSetSchemaCollection() { $driver = $this->getMockFormDriver(); $connection = $this->getMockBuilder(Connection::class) - ->setMethods(['connect']) + ->onlyMethods(['connect']) ->setConstructorArgs([['driver' => $driver]]) ->getMock(); @@ -1190,7 +1190,7 @@ public function testGetCachedCollection() { $driver = $this->getMockFormDriver(); $connection = $this->getMockBuilder(Connection::class) - ->setMethods(['connect']) + ->onlyMethods(['connect']) ->setConstructorArgs([[ 'driver' => $driver, 'name' => 'default', @@ -1204,7 +1204,7 @@ public function testGetCachedCollection() $driver = $this->getMockFormDriver(); $connection = $this->getMockBuilder(Connection::class) - ->setMethods(['connect']) + ->onlyMethods(['connect']) ->setConstructorArgs([[ 'driver' => $driver, 'name' => 'default', diff --git a/tests/TestCase/Database/Driver/MysqlTest.php b/tests/TestCase/Database/Driver/MysqlTest.php index b631b64db30..5671a402615 100644 --- a/tests/TestCase/Database/Driver/MysqlTest.php +++ b/tests/TestCase/Database/Driver/MysqlTest.php @@ -46,7 +46,7 @@ public function setup(): void public function testConnectionConfigDefault() { $driver = $this->getMockBuilder('Cake\Database\Driver\Mysql') - ->setMethods(['_connect', 'getConnection']) + ->onlyMethods(['_connect', 'getConnection']) ->getMock(); $dsn = 'mysql:host=localhost;port=3306;dbname=cake;charset=utf8mb4'; $expected = [ @@ -68,7 +68,7 @@ public function testConnectionConfigDefault() PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, ]; $connection = $this->getMockBuilder('StdClass') - ->setMethods(['exec']) + ->onlyMethods(['exec']) ->getMock(); $driver->expects($this->once())->method('_connect') @@ -103,7 +103,7 @@ public function testConnectionConfigCustom() ], ]; $driver = $this->getMockBuilder('Cake\Database\Driver\Mysql') - ->setMethods(['_connect', 'getConnection']) + ->onlyMethods(['_connect', 'getConnection']) ->setConstructorArgs([$config]) ->getMock(); $dsn = 'mysql:host=foo;port=3440;dbname=bar'; @@ -117,7 +117,7 @@ public function testConnectionConfigCustom() ]; $connection = $this->getMockBuilder('StdClass') - ->setMethods(['exec']) + ->onlyMethods(['exec']) ->getMock(); $connection->expects($this->at(0))->method('exec')->with('Execute this'); $connection->expects($this->at(1))->method('exec')->with('this too'); @@ -187,7 +187,7 @@ public function testVersion($dbVersion, $expectedVersion) { /** @var \PHPUnit\Framework\MockObject\MockObject&\Cake\Database\Connection $connection */ $connection = $this->getMockBuilder(Connection::class) - ->setMethods(['getAttribute']) + ->onlyMethods(['getAttribute']) ->getMock(); $connection->expects($this->once()) ->method('getAttribute') @@ -196,7 +196,7 @@ public function testVersion($dbVersion, $expectedVersion) /** @var \PHPUnit\Framework\MockObject\MockObject&\Cake\Database\Driver\Mysql $driver */ $driver = $this->getMockBuilder(Mysql::class) - ->setMethods(['connect']) + ->onlyMethods(['connect']) ->getMock(); $driver->setConnection($connection); diff --git a/tests/TestCase/Database/Driver/PostgresTest.php b/tests/TestCase/Database/Driver/PostgresTest.php index 6a7a067bf01..356a5996c00 100644 --- a/tests/TestCase/Database/Driver/PostgresTest.php +++ b/tests/TestCase/Database/Driver/PostgresTest.php @@ -33,7 +33,7 @@ class PostgresTest extends TestCase public function testConnectionConfigDefault() { $driver = $this->getMockBuilder('Cake\Database\Driver\Postgres') - ->setMethods(['_connect', 'getConnection']) + ->onlyMethods(['_connect', 'getConnection']) ->getMock(); $dsn = 'pgsql:host=localhost;port=5432;dbname=cake'; $expected = [ @@ -57,7 +57,7 @@ public function testConnectionConfigDefault() ]; $connection = $this->getMockBuilder('stdClass') - ->setMethods(['exec', 'quote']) + ->addMethods(['exec', 'quote']) ->getMock(); $connection->expects($this->any()) ->method('quote') @@ -100,7 +100,7 @@ public function testConnectionConfigCustom() 'init' => ['Execute this', 'this too'], ]; $driver = $this->getMockBuilder('Cake\Database\Driver\Postgres') - ->setMethods(['_connect', 'getConnection', 'setConnection']) + ->onlyMethods(['_connect', 'getConnection', 'setConnection']) ->setConstructorArgs([$config]) ->getMock(); $dsn = 'pgsql:host=foo;port=3440;dbname=bar'; @@ -113,7 +113,7 @@ public function testConnectionConfigCustom() ]; $connection = $this->getMockBuilder('stdClass') - ->setMethods(['exec', 'quote']) + ->addMethods(['exec', 'quote']) ->getMock(); $connection->expects($this->any()) ->method('quote') @@ -148,12 +148,12 @@ public function testConnectionConfigCustom() public function testInsertReturning() { $driver = $this->getMockBuilder('Cake\Database\Driver\Postgres') - ->setMethods(['_connect', 'getConnection']) + ->onlyMethods(['_connect', 'getConnection']) ->setConstructorArgs([[]]) ->getMock(); $connection = $this ->getMockBuilder('Cake\Database\Connection') - ->setMethods(['connect']) + ->onlyMethods(['connect']) ->disableOriginalConstructor() ->getMock(); @@ -182,12 +182,12 @@ public function testInsertReturning() public function testHavingReplacesAlias() { $driver = $this->getMockBuilder('Cake\Database\Driver\Postgres') - ->setMethods(['connect', 'getConnection', 'version']) + ->onlyMethods(['connect', 'getConnection', 'version']) ->setConstructorArgs([[]]) ->getMock(); $connection = $this->getMockBuilder('\Cake\Database\Connection') - ->setMethods(['connect', 'getDriver', 'setDriver']) + ->onlyMethods(['connect', 'getDriver', 'setDriver']) ->setConstructorArgs([['log' => false]]) ->getMock(); $connection->expects($this->any()) @@ -216,12 +216,12 @@ public function testHavingReplacesAlias() public function testHavingWhenNoAliasIsUsed() { $driver = $this->getMockBuilder('Cake\Database\Driver\Postgres') - ->setMethods(['connect', 'getConnection', 'version']) + ->onlyMethods(['connect', 'getConnection', 'version']) ->setConstructorArgs([[]]) ->getMock(); $connection = $this->getMockBuilder('\Cake\Database\Connection') - ->setMethods(['connect', 'getDriver', 'setDriver']) + ->onlyMethods(['connect', 'getDriver', 'setDriver']) ->setConstructorArgs([['log' => false]]) ->getMock(); $connection->expects($this->any()) diff --git a/tests/TestCase/Database/Driver/SqliteTest.php b/tests/TestCase/Database/Driver/SqliteTest.php index 5b7edda86a6..ea6d1a51e8f 100644 --- a/tests/TestCase/Database/Driver/SqliteTest.php +++ b/tests/TestCase/Database/Driver/SqliteTest.php @@ -33,7 +33,7 @@ class SqliteTest extends TestCase public function testConnectionConfigDefault() { $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlite') - ->setMethods(['_connect']) + ->onlyMethods(['_connect']) ->getMock(); $dsn = 'sqlite::memory:'; $expected = [ @@ -74,7 +74,7 @@ public function testConnectionConfigCustom() 'mask' => 0666, ]; $driver = $this->getMockBuilder('Cake\Database\driver\Sqlite') - ->setMethods(['_connect', 'getConnection']) + ->onlyMethods(['_connect', 'getConnection']) ->setConstructorArgs([$config]) ->getMock(); $dsn = 'sqlite:bar.db'; @@ -88,7 +88,7 @@ public function testConnectionConfigCustom() ]; $connection = $this->getMockBuilder('StdClass') - ->setMethods(['exec']) + ->addMethods(['exec']) ->getMock(); $connection->expects($this->at(0))->method('exec')->with('Execute this'); $connection->expects($this->at(1))->method('exec')->with('this too'); @@ -131,7 +131,8 @@ public function testSchemaValue($input, $expected) { $driver = new Sqlite(); $mock = $this->getMockBuilder(PDO::class) - ->setMethods(['quote', 'quoteIdentifier']) + ->onlyMethods(['quote']) + ->addMethods(['quoteIdentifier']) ->disableOriginalConstructor() ->getMock(); $mock->expects($this->any()) diff --git a/tests/TestCase/Database/Driver/SqlserverTest.php b/tests/TestCase/Database/Driver/SqlserverTest.php index a07e9e1a2bd..fe5e55219e1 100644 --- a/tests/TestCase/Database/Driver/SqlserverTest.php +++ b/tests/TestCase/Database/Driver/SqlserverTest.php @@ -100,7 +100,7 @@ public function dnsStringDataProvider() public function testDnsString($constructorArgs, $dnsString) { $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlserver') - ->setMethods(['_connect', 'getConnection']) + ->onlyMethods(['_connect', 'getConnection']) ->setConstructorArgs([$constructorArgs]) ->getMock(); @@ -137,7 +137,7 @@ public function testConnectionConfigCustom() 'settings' => ['config1' => 'value1', 'config2' => 'value2'], ]; $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlserver') - ->setMethods(['_connect', 'setConnection', 'getConnection']) + ->onlyMethods(['_connect', 'setConnection', 'getConnection']) ->setConstructorArgs([$config]) ->getMock(); $dsn = 'sqlsrv:Server=foo;Database=bar;MultipleActiveResultSets=false'; @@ -157,7 +157,7 @@ public function testConnectionConfigCustom() $expected['port'] = null; $connection = $this->getMockBuilder('stdClass') - ->setMethods(['exec', 'quote']) + ->addMethods(['exec', 'quote']) ->getMock(); $connection->expects($this->any()) ->method('quote') @@ -199,7 +199,7 @@ public function testConnectionPersistentFalse() 'encoding' => 'a-language', ]; $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlserver') - ->setMethods(['_connect', 'connection']) + ->onlyMethods(['_connect']) ->setConstructorArgs([$config]) ->getMock(); $dsn = 'sqlsrv:Server=foo;Database=bar;MultipleActiveResultSets=false'; @@ -246,7 +246,7 @@ public function testConnectionPersistentTrueException() 'database' => 'bar', ]; $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlserver') - ->setMethods(['_connect', 'connection']) + ->onlyMethods(['_connect', 'getConnection']) ->setConstructorArgs([$config]) ->getMock(); $driver->connect(); @@ -260,14 +260,14 @@ public function testConnectionPersistentTrueException() public function testSelectLimitVersion12() { $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlserver') - ->setMethods(['_connect', 'getConnection', 'version']) + ->onlyMethods(['_connect', 'getConnection', 'version']) ->setConstructorArgs([[]]) ->getMock(); $driver->method('version') ->will($this->returnValue('12')); $connection = $this->getMockBuilder('Cake\Database\Connection') - ->setMethods(['connect', 'getDriver', 'setDriver']) + ->onlyMethods(['connect', 'getDriver', 'setDriver']) ->setConstructorArgs([['log' => false]]) ->getMock(); $connection->method('getDriver') @@ -309,7 +309,7 @@ public function testSelectLimitVersion12() public function testSelectLimitOldServer() { $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlserver') - ->setMethods(['_connect', 'getConnection', 'version']) + ->onlyMethods(['_connect', 'getConnection', 'version']) ->setConstructorArgs([[]]) ->getMock(); $driver->expects($this->any()) @@ -317,7 +317,7 @@ public function testSelectLimitOldServer() ->will($this->returnValue('8')); $connection = $this->getMockBuilder('Cake\Database\Connection') - ->setMethods(['connect', 'getDriver', 'setDriver']) + ->onlyMethods(['connect', 'getDriver', 'setDriver']) ->setConstructorArgs([['log' => false]]) ->getMock(); $connection->expects($this->any()) @@ -375,11 +375,11 @@ public function testSelectLimitOldServer() public function testInsertUsesOutput() { $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlserver') - ->setMethods(['_connect', 'getConnection']) + ->onlyMethods(['_connect', 'getConnection']) ->setConstructorArgs([[]]) ->getMock(); $connection = $this->getMockBuilder('Cake\Database\Connection') - ->setMethods(['connect', 'getDriver', 'setDriver']) + ->onlyMethods(['connect', 'getDriver', 'setDriver']) ->setConstructorArgs([['log' => false]]) ->getMock(); $connection->expects($this->any()) @@ -401,7 +401,7 @@ public function testInsertUsesOutput() public function testHavingReplacesAlias() { $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlserver') - ->setMethods(['connect', 'getConnection', 'version']) + ->onlyMethods(['connect', 'getConnection', 'version']) ->setConstructorArgs([[]]) ->getMock(); $driver->expects($this->any()) @@ -409,7 +409,7 @@ public function testHavingReplacesAlias() ->will($this->returnValue('8')); $connection = $this->getMockBuilder('\Cake\Database\Connection') - ->setMethods(['connect', 'getDriver', 'setDriver']) + ->onlyMethods(['connect', 'getDriver', 'setDriver']) ->setConstructorArgs([['log' => false]]) ->getMock(); $connection->expects($this->any()) @@ -438,7 +438,7 @@ public function testHavingReplacesAlias() public function testHavingWhenNoAliasIsUsed() { $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlserver') - ->setMethods(['connect', 'getConnection', 'version']) + ->onlyMethods(['connect', 'getConnection', 'version']) ->setConstructorArgs([[]]) ->getMock(); $driver->expects($this->any()) @@ -446,7 +446,7 @@ public function testHavingWhenNoAliasIsUsed() ->will($this->returnValue('8')); $connection = $this->getMockBuilder('\Cake\Database\Connection') - ->setMethods(['connect', 'getDriver', 'setDriver']) + ->onlyMethods(['connect', 'getDriver', 'setDriver']) ->setConstructorArgs([['log' => false]]) ->getMock(); $connection->expects($this->any()) diff --git a/tests/TestCase/Database/DriverTest.php b/tests/TestCase/Database/DriverTest.php index dc12b7bf111..93c3b1fe492 100644 --- a/tests/TestCase/Database/DriverTest.php +++ b/tests/TestCase/Database/DriverTest.php @@ -103,7 +103,7 @@ public function testSupportsQuoting() { $connection = $this->getMockBuilder(PDO::class) ->disableOriginalConstructor() - ->setMethods(['getAttribute']) + ->onlyMethods(['getAttribute']) ->getMock(); $connection @@ -143,7 +143,7 @@ public function testSchemaValueConnectionQuoting() $connection = $this->getMockBuilder(PDO::class) ->disableOriginalConstructor() - ->setMethods(['quote']) + ->onlyMethods(['quote']) ->getMock(); $connection @@ -165,7 +165,7 @@ public function testLastInsertId() { $connection = $this->getMockBuilder(Mysql::class) ->disableOriginalConstructor() - ->setMethods(['lastInsertId']) + ->onlyMethods(['lastInsertId']) ->getMock(); $connection @@ -188,7 +188,7 @@ public function testIsConnected() $connection = $this->getMockBuilder(PDO::class) ->disableOriginalConstructor() - ->setMethods(['query']) + ->onlyMethods(['query']) ->getMock(); $connection @@ -224,7 +224,7 @@ public function testAutoQuoting() public function testCompileQuery() { $compiler = $this->getMockBuilder(QueryCompiler::class) - ->setMethods(['compile']) + ->onlyMethods(['compile']) ->getMock(); $compiler @@ -233,7 +233,7 @@ public function testCompileQuery() ->willReturn('1'); $driver = $this->getMockBuilder(Driver::class) - ->setMethods(['newCompiler', 'queryTranslator']) + ->onlyMethods(['newCompiler', 'queryTranslator']) ->getMockForAbstractClass(); $driver diff --git a/tests/TestCase/Database/QueryTest.php b/tests/TestCase/Database/QueryTest.php index f9514ac6f3c..4638cebe08e 100644 --- a/tests/TestCase/Database/QueryTest.php +++ b/tests/TestCase/Database/QueryTest.php @@ -4233,7 +4233,7 @@ public function testRowCountAndClose() $this->loadFixtures('Authors'); $statementMock = $this->getMockBuilder(StatementInterface::class) - ->setMethods(['rowCount', 'closeCursor']) + ->onlyMethods(['rowCount', 'closeCursor']) ->getMockForAbstractClass(); $statementMock->expects($this->once()) @@ -4245,7 +4245,7 @@ public function testRowCountAndClose() /** @var \Cake\ORM\Query|\PHPUnit\Framework\MockObject\MockObject $queryMock */ $queryMock = $this->getMockBuilder(Query::class) - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->setConstructorArgs([$this->connection]) ->getMock(); diff --git a/tests/TestCase/Database/Schema/MysqlSchemaTest.php b/tests/TestCase/Database/Schema/MysqlSchemaTest.php index 692d3739336..b482845ee1b 100644 --- a/tests/TestCase/Database/Schema/MysqlSchemaTest.php +++ b/tests/TestCase/Database/Schema/MysqlSchemaTest.php @@ -1391,7 +1391,8 @@ protected function _getMockedDriver() { $driver = new Mysql(); $mock = $this->getMockBuilder(PDO::class) - ->setMethods(['quote', 'quoteIdentifier', 'getAttribute']) + ->onlyMethods(['quote', 'getAttribute']) + ->addMethods(['quoteIdentifier']) ->disableOriginalConstructor() ->getMock(); $mock->expects($this->any()) diff --git a/tests/TestCase/Database/Schema/PostgresSchemaTest.php b/tests/TestCase/Database/Schema/PostgresSchemaTest.php index abf6e5ed0bd..b33780f0181 100644 --- a/tests/TestCase/Database/Schema/PostgresSchemaTest.php +++ b/tests/TestCase/Database/Schema/PostgresSchemaTest.php @@ -1386,7 +1386,7 @@ protected function _getMockedDriver() { $driver = new Postgres(); $mock = $this->getMockBuilder(PDO::class) - ->setMethods(['quote']) + ->onlyMethods(['quote']) ->disableOriginalConstructor() ->getMock(); $mock->expects($this->any()) diff --git a/tests/TestCase/Database/Schema/SqliteSchemaTest.php b/tests/TestCase/Database/Schema/SqliteSchemaTest.php index ef013166070..7675d729396 100644 --- a/tests/TestCase/Database/Schema/SqliteSchemaTest.php +++ b/tests/TestCase/Database/Schema/SqliteSchemaTest.php @@ -1029,7 +1029,7 @@ public function testTruncateSql() ->will($this->returnValue($driver)); $statement = $this->getMockBuilder('\PDOStatement') - ->setMethods(['execute', 'rowCount', 'closeCursor', 'fetchAll']) + ->onlyMethods(['execute', 'rowCount', 'closeCursor', 'fetchAll']) ->getMock(); $driver->getConnection()->expects($this->once()) ->method('prepare') @@ -1062,7 +1062,7 @@ public function testTruncateSqlNoSequences() ->will($this->returnValue($driver)); $statement = $this->getMockBuilder('\PDOStatement') - ->setMethods(['execute', 'rowCount', 'closeCursor', 'fetchAll']) + ->onlyMethods(['execute', 'rowCount', 'closeCursor', 'fetchAll']) ->getMock(); $driver->getConnection() ->expects($this->once()) @@ -1089,7 +1089,7 @@ protected function _getMockedDriver() { $driver = new Sqlite(); $mock = $this->getMockBuilder(PDO::class) - ->setMethods(['quote', 'prepare']) + ->onlyMethods(['quote', 'prepare']) ->disableOriginalConstructor() ->getMock(); $mock->expects($this->any()) diff --git a/tests/TestCase/Database/Schema/SqlserverSchemaTest.php b/tests/TestCase/Database/Schema/SqlserverSchemaTest.php index fb875040232..b870c145187 100644 --- a/tests/TestCase/Database/Schema/SqlserverSchemaTest.php +++ b/tests/TestCase/Database/Schema/SqlserverSchemaTest.php @@ -1137,7 +1137,7 @@ protected function _getMockedDriver() { $driver = new Sqlserver(); $mock = $this->getMockBuilder(PDO::class) - ->setMethods(['quote']) + ->onlyMethods(['quote']) ->disableOriginalConstructor() ->getMock(); $mock->expects($this->any()) diff --git a/tests/TestCase/Database/Type/StringTypeTest.php b/tests/TestCase/Database/Type/StringTypeTest.php index dc73c396cd8..d491cf1659c 100644 --- a/tests/TestCase/Database/Type/StringTypeTest.php +++ b/tests/TestCase/Database/Type/StringTypeTest.php @@ -68,7 +68,7 @@ public function testToPHP() public function testToDatabase() { $obj = $this->getMockBuilder('StdClass') - ->setMethods(['__toString']) + ->addMethods(['__toString']) ->getMock(); $obj->method('__toString')->will($this->returnValue('toString called')); diff --git a/tests/TestCase/Database/ValueBinderTest.php b/tests/TestCase/Database/ValueBinderTest.php index 4cb1659bfaf..cccc2759305 100644 --- a/tests/TestCase/Database/ValueBinderTest.php +++ b/tests/TestCase/Database/ValueBinderTest.php @@ -146,7 +146,7 @@ public function testAttachTo() $valueBinder = new ValueBinder(); $statementMock = $this->getMockBuilder('Cake\Database\Statement\StatementDecorator') ->disableOriginalConstructor() - ->setMethods(['bindValue']) + ->onlyMethods(['bindValue']) ->getMock(); $statementMock->expects($this->at(0))->method('bindValue')->with('c0', 'value0', 'string'); diff --git a/tests/TestCase/Datasource/PaginatorTestTrait.php b/tests/TestCase/Datasource/PaginatorTestTrait.php index 3aacbc3e461..5f1fe768e0e 100644 --- a/tests/TestCase/Datasource/PaginatorTestTrait.php +++ b/tests/TestCase/Datasource/PaginatorTestTrait.php @@ -1384,7 +1384,7 @@ public function testPaginateQueryWithLimit() protected function _getMockPosts($methods = []) { return $this->getMockBuilder('TestApp\Model\Table\PaginatorPostsTable') - ->setMethods($methods) + ->onlyMethods($methods) ->setConstructorArgs([[ 'connection' => ConnectionManager::get('test'), 'alias' => 'PaginatorPosts', @@ -1410,7 +1410,8 @@ protected function _getMockFindQuery($table = null) { /** @var \Cake\ORM\Query|\PHPUnit\Framework\MockObject\MockObject $query */ $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['total', 'all', 'count', 'applyOptions']) + ->onlyMethods(['all', 'count', 'applyOptions']) + ->addMethods(['total']) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/TestCase/Error/ConsoleErrorHandlerTest.php b/tests/TestCase/Error/ConsoleErrorHandlerTest.php index 92cc94d797d..f5beab4719f 100644 --- a/tests/TestCase/Error/ConsoleErrorHandlerTest.php +++ b/tests/TestCase/Error/ConsoleErrorHandlerTest.php @@ -49,7 +49,7 @@ public function setUp(): void parent::setUp(); $this->stderr = new ConsoleOutput(); $this->Error = $this->getMockBuilder('Cake\Error\ConsoleErrorHandler') - ->setMethods(['_stop']) + ->onlyMethods(['_stop']) ->setConstructorArgs([['stderr' => $this->stderr]]) ->getMock(); Log::drop('stdout'); diff --git a/tests/TestCase/Error/ExceptionRendererTest.php b/tests/TestCase/Error/ExceptionRendererTest.php index 453763760f4..f6615c1a108 100644 --- a/tests/TestCase/Error/ExceptionRendererTest.php +++ b/tests/TestCase/Error/ExceptionRendererTest.php @@ -690,7 +690,7 @@ public function testMissingRenderSafe() /** @var \Cake\Controller\Controller|\PHPUnit\Framework\MockObject\MockObject $controller */ $controller = $this->getMockBuilder('Cake\Controller\Controller') - ->setMethods(['render']) + ->onlyMethods(['render']) ->getMock(); $controller->viewBuilder()->setHelpers(['Fail', 'Boom']); $controller->setRequest(new ServerRequest()); @@ -720,7 +720,7 @@ public function testRenderExceptionInBeforeRender() /** @var \Cake\Controller\Controller|\PHPUnit\Framework\MockObject\MockObject $controller */ $controller = $this->getMockBuilder('Cake\Controller\Controller') - ->setMethods(['beforeRender']) + ->onlyMethods(['beforeRender']) ->getMock(); $controller->request = new ServerRequest(); $controller->expects($this->any()) @@ -807,7 +807,7 @@ public function testMissingPluginRenderSafe() /** @var \Cake\Controller\Controller|\PHPUnit\Framework\MockObject\MockObject $controller */ $controller = $this->getMockBuilder('Cake\Controller\Controller') - ->setMethods(['render']) + ->onlyMethods(['render']) ->getMock(); $controller->setPlugin('TestPlugin'); $controller->request = new ServerRequest(); @@ -839,7 +839,7 @@ public function testMissingPluginRenderSafeWithPlugin() /** @var \Cake\Controller\Controller|\PHPUnit\Framework\MockObject\MockObject $controller */ $controller = $this->getMockBuilder('Cake\Controller\Controller') - ->setMethods(['render']) + ->onlyMethods(['render']) ->getMock(); $controller->setPlugin('TestPlugin'); $controller->request = new ServerRequest(); diff --git a/tests/TestCase/Error/Middleware/ErrorHandlerMiddlewareTest.php b/tests/TestCase/Error/Middleware/ErrorHandlerMiddlewareTest.php index ead613f5d78..c279c948970 100644 --- a/tests/TestCase/Error/Middleware/ErrorHandlerMiddlewareTest.php +++ b/tests/TestCase/Error/Middleware/ErrorHandlerMiddlewareTest.php @@ -110,7 +110,7 @@ public function testRendererFactory() $this->assertInstanceOf('LogicException', $exception); $response = new Response(); $mock = $this->getMockBuilder(ExceptionRendererInterface::class) - ->setMethods(['render']) + ->onlyMethods(['render']) ->getMock(); $mock->expects($this->once()) ->method('render') @@ -356,7 +356,7 @@ public function testHandleExceptionRenderingFails() $factory = function ($exception) { $mock = $this->getMockBuilder(ExceptionRendererInterface::class) - ->setMethods(['render']) + ->onlyMethods(['render']) ->getMock(); $mock->expects($this->once()) ->method('render') diff --git a/tests/TestCase/Event/EventManagerTest.php b/tests/TestCase/Event/EventManagerTest.php index 5f0d57cb5e9..febf07e9366 100644 --- a/tests/TestCase/Event/EventManagerTest.php +++ b/tests/TestCase/Event/EventManagerTest.php @@ -334,7 +334,7 @@ public function testOnSubscriber() $manager = new EventManager(); /** @var \TestApp\TestCase\Event\CustomTestEventListenerInterface|\PHPUnit\Framework\MockObject\MockObject $listener */ $listener = $this->getMockBuilder(CustomTestEventListenerInterface::class) - ->setMethods(['secondListenerFunction']) + ->onlyMethods(['secondListenerFunction']) ->getMock(); $manager->on($listener); @@ -361,7 +361,7 @@ public function testOnSubscriberMultiple() { $manager = new EventManager(); $listener = $this->getMockBuilder(CustomTestEventListenerInterface::class) - ->setMethods(['listenerFunction', 'thirdListenerFunction']) + ->onlyMethods(['listenerFunction', 'thirdListenerFunction']) ->getMock(); $manager->on($listener); $event = new Event('multiple.handlers'); @@ -383,7 +383,7 @@ public function testDetachSubscriber() { $manager = new EventManager(); $listener = $this->getMockBuilder(CustomTestEventListenerInterface::class) - ->setMethods(['secondListenerFunction']) + ->onlyMethods(['secondListenerFunction']) ->getMock(); $manager->on($listener); $expected = [ @@ -422,7 +422,7 @@ public function testGlobalDispatcherGetter() public function testDispatchWithGlobal() { $generalManager = $this->getMockBuilder('Cake\Event\EventManager') - ->setMethods(['prioritisedListeners']) + ->onlyMethods(['prioritisedListeners']) ->getMock(); $manager = new EventManager(); $event = new Event('fake.event'); diff --git a/tests/TestCase/Form/FormTest.php b/tests/TestCase/Form/FormTest.php index 2ac9fedc7fe..325f050f3f0 100644 --- a/tests/TestCase/Form/FormTest.php +++ b/tests/TestCase/Form/FormTest.php @@ -79,7 +79,7 @@ public function testSetGetSchema() public function testGetValidator() { $form = $this->getMockBuilder(Form::class) - ->setMethods(['buildValidator']) + ->addMethods(['buildValidator']) ->getMock(); $form->expects($this->once()) @@ -182,7 +182,7 @@ public function testSetErrors() public function testExecuteInvalid() { $form = $this->getMockBuilder('Cake\Form\Form') - ->setMethods(['_execute']) + ->onlyMethods(['_execute']) ->getMock(); $form->getValidator() ->add('email', 'format', ['rule' => 'email']); diff --git a/tests/TestCase/Http/Client/Adapter/StreamTest.php b/tests/TestCase/Http/Client/Adapter/StreamTest.php index 1fcda5807a7..4b84cd6a6c9 100644 --- a/tests/TestCase/Http/Client/Adapter/StreamTest.php +++ b/tests/TestCase/Http/Client/Adapter/StreamTest.php @@ -38,7 +38,7 @@ public function setUp(): void { parent::setUp(); $this->stream = $this->getMockBuilder(Stream::class) - ->setMethods(['_send']) + ->onlyMethods(['_send']) ->getMock(); stream_wrapper_unregister('http'); stream_wrapper_register('http', CakeStreamWrapper::class); diff --git a/tests/TestCase/Http/Client/Auth/DigestTest.php b/tests/TestCase/Http/Client/Auth/DigestTest.php index b17f44e18ce..1bec7de3eeb 100644 --- a/tests/TestCase/Http/Client/Auth/DigestTest.php +++ b/tests/TestCase/Http/Client/Auth/DigestTest.php @@ -55,7 +55,7 @@ public function setUp(): void protected function getClientMock() { return $this->getMockBuilder(Client::class) - ->setMethods(['send']) + ->onlyMethods(['send']) ->getMock(); } diff --git a/tests/TestCase/Http/ClientTest.php b/tests/TestCase/Http/ClientTest.php index 2bc91649df1..57a82473772 100644 --- a/tests/TestCase/Http/ClientTest.php +++ b/tests/TestCase/Http/ClientTest.php @@ -208,7 +208,7 @@ public function testGetSimpleWithHeadersAndCookies() ]; $mock = $this->getMockBuilder(Stream::class) - ->setMethods(['send']) + ->onlyMethods(['send']) ->getMock(); $mock->expects($this->once()) ->method('send') @@ -243,7 +243,7 @@ public function testGetNoData() $response = new Response(); $mock = $this->getMockBuilder(Stream::class) - ->setMethods(['send']) + ->onlyMethods(['send']) ->getMock(); $mock->expects($this->once()) ->method('send') @@ -277,7 +277,7 @@ public function testGetQuerystring() $response = new Response(); $mock = $this->getMockBuilder(Stream::class) - ->setMethods(['send']) + ->onlyMethods(['send']) ->getMock(); $mock->expects($this->once()) ->method('send') @@ -313,7 +313,7 @@ public function testGetQuerystringString() $response = new Response(); $mock = $this->getMockBuilder(Stream::class) - ->setMethods(['send']) + ->onlyMethods(['send']) ->getMock(); $mock->expects($this->once()) ->method('send') @@ -350,7 +350,7 @@ public function testGetWithContent() $response = new Response(); $mock = $this->getMockBuilder(Stream::class) - ->setMethods(['send']) + ->onlyMethods(['send']) ->getMock(); $mock->expects($this->once()) ->method('send') @@ -382,7 +382,7 @@ public function testInvalidAuthenticationType() { $this->expectException(\Cake\Core\Exception\Exception::class); $mock = $this->getMockBuilder(Stream::class) - ->setMethods(['send']) + ->onlyMethods(['send']) ->getMock(); $mock->expects($this->never()) ->method('send'); @@ -406,7 +406,7 @@ public function testGetWithAuthenticationAndProxy() $response = new Response(); $mock = $this->getMockBuilder(Stream::class) - ->setMethods(['send']) + ->onlyMethods(['send']) ->getMock(); $headers = [ 'Authorization' => 'Basic ' . base64_encode('mark:secret'), @@ -464,7 +464,7 @@ public function testMethodsSimple($method) $response = new Response(); $mock = $this->getMockBuilder(Stream::class) - ->setMethods(['send']) + ->onlyMethods(['send']) ->getMock(); $mock->expects($this->once()) ->method('send') @@ -516,7 +516,7 @@ public function testPostWithTypeKey($type, $mime) ]; $mock = $this->getMockBuilder(Stream::class) - ->setMethods(['send']) + ->onlyMethods(['send']) ->getMock(); $mock->expects($this->once()) ->method('send') @@ -547,7 +547,7 @@ public function testPostWithStringDataDefaultsToFormEncoding() $data = 'some=value&more=data'; $mock = $this->getMockBuilder(Stream::class) - ->setMethods(['send']) + ->onlyMethods(['send']) ->getMock(); $mock->expects($this->any()) ->method('send') @@ -577,7 +577,7 @@ public function testExceptionOnUnknownType() { $this->expectException(\Cake\Core\Exception\Exception::class); $mock = $this->getMockBuilder(Stream::class) - ->setMethods(['send']) + ->onlyMethods(['send']) ->getMock(); $mock->expects($this->never()) ->method('send'); @@ -597,7 +597,7 @@ public function testExceptionOnUnknownType() public function testCookieStorage() { $adapter = $this->getMockBuilder(Stream::class) - ->setMethods(['send']) + ->onlyMethods(['send']) ->getMock(); $headers = [ @@ -699,7 +699,7 @@ public function testHeadQuerystring() $response = new Response(); $mock = $this->getMockBuilder(Stream::class) - ->setMethods(['send']) + ->onlyMethods(['send']) ->getMock(); $mock->expects($this->once()) ->method('send') @@ -732,7 +732,7 @@ public function testRedirects() $url = 'http://cakephp.org'; $adapter = $this->getMockBuilder(Client\Adapter\Stream::class) - ->setMethods(['send']) + ->onlyMethods(['send']) ->getMock(); $redirect = new Response([ @@ -824,7 +824,7 @@ public function testSendRequest() ]; $mock = $this->getMockBuilder(Stream::class) - ->setMethods(['send']) + ->onlyMethods(['send']) ->getMock(); $mock->expects($this->once()) ->method('send') @@ -859,7 +859,7 @@ public function testSendRequest() public function testRedirectDifferentSubDomains() { $adapter = $this->getMockBuilder(Client\Adapter\Stream::class) - ->setMethods(['send']) + ->onlyMethods(['send']) ->getMock(); $url = 'http://auth.example.org'; diff --git a/tests/TestCase/Http/ResponseEmitterTest.php b/tests/TestCase/Http/ResponseEmitterTest.php index f592494c16e..7ff2a2de86b 100644 --- a/tests/TestCase/Http/ResponseEmitterTest.php +++ b/tests/TestCase/Http/ResponseEmitterTest.php @@ -47,7 +47,7 @@ public function setUp(): void $GLOBALS['mockedHeaders'] = []; $this->emitter = $this->getMockBuilder(ResponseEmitter::class) - ->setMethods(['setCookie']) + ->onlyMethods(['setCookie']) ->getMock(); $this->emitter->expects($this->any()) diff --git a/tests/TestCase/Http/ServerTest.php b/tests/TestCase/Http/ServerTest.php index 817bc53ade7..acf42754346 100644 --- a/tests/TestCase/Http/ServerTest.php +++ b/tests/TestCase/Http/ServerTest.php @@ -136,7 +136,8 @@ public function testRunCallingPluginHooks() /** @var \TestApp\Http\MiddlewareApplication|\PHPUnit\Framework\MockObject\MockObject $app */ $app = $this->getMockBuilder(MiddlewareApplication::class) - ->setMethods(['pluginBootstrap', 'pluginEvents', 'pluginMiddleware']) + ->onlyMethods(['pluginBootstrap', 'pluginMiddleware']) + ->addMethods(['pluginEvents']) ->setConstructorArgs([$this->config]) ->getMock(); $app->expects($this->at(0)) diff --git a/tests/TestCase/Log/Engine/SyslogLogTest.php b/tests/TestCase/Log/Engine/SyslogLogTest.php index 8c9e8dcbbca..68a579ccc5f 100644 --- a/tests/TestCase/Log/Engine/SyslogLogTest.php +++ b/tests/TestCase/Log/Engine/SyslogLogTest.php @@ -33,13 +33,13 @@ public function testOpenLog() { /** @var \Cake\Log\Engine\SyslogLog|\PHPUnit\Framework\MockObject\MockObject $log */ $log = $this->getMockBuilder(SyslogLog::class) - ->setMethods(['_open', '_write']) + ->onlyMethods(['_open', '_write']) ->getMock(); $log->expects($this->once())->method('_open')->with('', LOG_ODELAY, LOG_USER); $log->log('debug', 'message'); $log = $this->getMockBuilder(SyslogLog::class) - ->setMethods(['_open', '_write']) + ->onlyMethods(['_open', '_write']) ->getMock(); $log->setConfig([ 'prefix' => 'thing', @@ -62,7 +62,7 @@ public function testWriteOneLine($type, $expected) { /** @var \Cake\Log\Engine\SyslogLog|\PHPUnit\Framework\MockObject\MockObject $log */ $log = $this->getMockBuilder(SyslogLog::class) - ->setMethods(['_open', '_write']) + ->onlyMethods(['_open', '_write']) ->getMock(); $log->expects($this->once())->method('_write')->with($expected, $type . ': Foo'); $log->log($type, 'Foo'); @@ -77,7 +77,7 @@ public function testWriteMultiLine() { /** @var \Cake\Log\Engine\SyslogLog|\PHPUnit\Framework\MockObject\MockObject $log */ $log = $this->getMockBuilder(SyslogLog::class) - ->setMethods(['_open', '_write']) + ->onlyMethods(['_open', '_write']) ->getMock(); $log->expects($this->at(1))->method('_write')->with(LOG_DEBUG, 'debug: Foo'); $log->expects($this->at(2))->method('_write')->with(LOG_DEBUG, 'debug: Bar'); diff --git a/tests/TestCase/Mailer/MailerTest.php b/tests/TestCase/Mailer/MailerTest.php index 9cf7fabd6f6..9a8009680f1 100644 --- a/tests/TestCase/Mailer/MailerTest.php +++ b/tests/TestCase/Mailer/MailerTest.php @@ -433,7 +433,8 @@ public function testRenderWithLayoutAndAttachment() public function testSend() { $mailer = $this->getMockBuilder(Mailer::class) - ->setMethods(['test', 'deliver']) + ->onlyMethods(['deliver']) + ->addMethods(['test']) ->getMock(); $mailer->expects($this->once()) ->method('test') @@ -1195,7 +1196,8 @@ public function testSendAttachment() public function testSendWithUnsetTemplateDefaultsToActionName() { $mailer = $this->getMockBuilder(Mailer::class) - ->setMethods(['test', 'deliver', 'restore']) + ->onlyMethods(['deliver', 'restore']) + ->addMethods(['test']) ->getMock(); $mailer->expects($this->once()) ->method('test') @@ -1293,7 +1295,8 @@ public function testReset() public function testSendFailsEmailIsReset() { $mailer = $this->getMockBuilder(Mailer::class) - ->setMethods(['welcome', 'restore', 'deliver']) + ->onlyMethods(['restore', 'deliver']) + ->addMethods(['welcome']) ->getMock(); $mailer->expects($this->once()) @@ -1374,7 +1377,8 @@ public function testSendWithLogAndScope() public function testDefaultProfileRestoration() { $mailer = $this->getMockBuilder(Mailer::class) - ->setMethods(['test', 'deliver']) + ->onlyMethods(['deliver']) + ->addMethods(['test']) ->setConstructorArgs([['template' => 'cakephp']]) ->getMock(); $mailer->expects($this->once()) diff --git a/tests/TestCase/Mailer/Transport/MailTransportTest.php b/tests/TestCase/Mailer/Transport/MailTransportTest.php index 5110b315dbf..73ef572f36d 100644 --- a/tests/TestCase/Mailer/Transport/MailTransportTest.php +++ b/tests/TestCase/Mailer/Transport/MailTransportTest.php @@ -41,7 +41,7 @@ public function setUp(): void { parent::setUp(); $this->MailTransport = $this->getMockBuilder('Cake\Mailer\Transport\MailTransport') - ->setMethods(['_mail']) + ->onlyMethods(['_mail']) ->getMock(); $this->MailTransport->setConfig(['additionalParameters' => '-f']); } diff --git a/tests/TestCase/Mailer/Transport/SmtpTransportTest.php b/tests/TestCase/Mailer/Transport/SmtpTransportTest.php index 94f682fbe4c..16da1247d47 100644 --- a/tests/TestCase/Mailer/Transport/SmtpTransportTest.php +++ b/tests/TestCase/Mailer/Transport/SmtpTransportTest.php @@ -59,7 +59,7 @@ public function setUp(): void { parent::setUp(); $this->socket = $this->getMockBuilder('Cake\Network\Socket') - ->setMethods(['read', 'write', 'connect', 'disconnect', 'enableCrypto']) + ->onlyMethods(['read', 'write', 'connect', 'disconnect', 'enableCrypto']) ->getMock(); $this->SmtpTransport = new SmtpTestTransport(); @@ -645,7 +645,7 @@ public function testKeepAlive() /** @var \Cake\Mailer\Message $message */ $message = $this->getMockBuilder(Message::class) - ->setMethods(['getBody']) + ->onlyMethods(['getBody']) ->getMock(); $message->setFrom('noreply@cakephp.org', 'CakePHP Test'); $message->setTo('cake@cakephp.org', 'CakePHP'); @@ -701,7 +701,7 @@ public function testSendDefaults() { /** @var \Cake\Mailer\Message $message */ $message = $this->getMockBuilder(Message::class) - ->setMethods(['getBody']) + ->onlyMethods(['getBody']) ->getMock(); $message->setFrom('noreply@cakephp.org', 'CakePHP Test'); $message->setTo('cake@cakephp.org', 'CakePHP'); @@ -738,7 +738,7 @@ public function testSendMessageTooBigOnWindows() { /** @var \Cake\Mailer\Message $message */ $message = $this->getMockBuilder(Message::class) - ->setMethods(['getBody']) + ->onlyMethods(['getBody']) ->getMock(); $message->setFrom('noreply@cakephp.org', 'CakePHP Test'); $message->setTo('cake@cakephp.org', 'CakePHP'); diff --git a/tests/TestCase/Network/SocketTest.php b/tests/TestCase/Network/SocketTest.php index 53884b9d542..85c82449903 100644 --- a/tests/TestCase/Network/SocketTest.php +++ b/tests/TestCase/Network/SocketTest.php @@ -528,7 +528,7 @@ public function testConnectToUnixFileSocket() { $socketName = 'unix:///tmp/test.socket'; $socket = $this->getMockBuilder(Socket::class) - ->setMethods(['_getStreamSocketClient']) + ->onlyMethods(['_getStreamSocketClient']) ->getMock(); $socket->expects($this->once()) ->method('_getStreamSocketClient') diff --git a/tests/TestCase/ORM/Association/BelongsToManyTest.php b/tests/TestCase/ORM/Association/BelongsToManyTest.php index f6f5ed95d37..70d83dfc903 100644 --- a/tests/TestCase/ORM/Association/BelongsToManyTest.php +++ b/tests/TestCase/ORM/Association/BelongsToManyTest.php @@ -52,7 +52,7 @@ public function setUp(): void { parent::setUp(); $this->tag = $this->getMockBuilder(Table::class) - ->setMethods(['find', 'delete']) + ->onlyMethods(['find', 'delete']) ->setConstructorArgs([['alias' => 'Tags', 'table' => 'tags']]) ->getMock(); $this->tag->setSchema([ @@ -63,7 +63,7 @@ public function setUp(): void ], ]); $this->article = $this->getMockBuilder(Table::class) - ->setMethods(['find', 'delete']) + ->onlyMethods(['find', 'delete']) ->setConstructorArgs([['alias' => 'Articles', 'table' => 'articles']]) ->getMock(); $this->article->setSchema([ @@ -197,7 +197,7 @@ public function testJunction() public function testJunctionConnection() { $mock = $this->getMockBuilder(Connection::class) - ->setMethods(['setDriver']) + ->onlyMethods(['setDriver']) ->setConstructorArgs([['name' => 'other_source']]) ->getMock(); ConnectionManager::setConfig('other_source', $mock); @@ -370,7 +370,7 @@ public function testFinderOption() public function testCascadeDelete() { $articleTag = $this->getMockBuilder(Table::class) - ->setMethods(['deleteAll']) + ->onlyMethods(['deleteAll']) ->getMock(); $config = [ 'sourceTable' => $this->article, @@ -402,7 +402,7 @@ public function testCascadeDelete() public function testCascadeDeleteDependent() { $articleTag = $this->getMockBuilder(Table::class) - ->setMethods(['delete', 'deleteAll']) + ->onlyMethods(['delete', 'deleteAll']) ->getMock(); $config = [ 'sourceTable' => $this->article, @@ -608,7 +608,7 @@ public function testLinkSuccessWithMocks() { $connection = ConnectionManager::get('test'); $joint = $this->getMockBuilder(Table::class) - ->setMethods(['save', 'getPrimaryKey']) + ->onlyMethods(['save', 'getPrimaryKey']) ->setConstructorArgs([['alias' => 'ArticlesTags', 'connection' => $connection]]) ->getMock(); @@ -664,7 +664,7 @@ public function testLinkSetSourceToJunctionEntities() $connection = ConnectionManager::get('test'); /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $joint */ $joint = $this->getMockBuilder(Table::class) - ->setMethods(['save', 'getPrimaryKey']) + ->onlyMethods(['save', 'getPrimaryKey']) ->setConstructorArgs([['alias' => 'ArticlesTags', 'connection' => $connection]]) ->getMock(); $joint->setRegistryAlias('Plugin.ArticlesTags'); @@ -1020,12 +1020,12 @@ public function testSaveAssociatedEmptySetSuccess($value) { /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockBuilder $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['table']) + ->addMethods(['table']) ->getMock(); $table->setSchema([]); /** @var \Cake\ORM\Association\BelongsToMany|\PHPUnit\Framework\MockObject\MockObject $assoc */ $assoc = $this->getMockBuilder(BelongsToMany::class) - ->setMethods(['_saveTarget', 'replaceLinks']) + ->onlyMethods(['_saveTarget', 'replaceLinks']) ->setConstructorArgs(['tags', ['sourceTable' => $table]]) ->getMock(); $entity = new Entity([ @@ -1051,12 +1051,12 @@ public function testSaveAssociatedEmptySetUpdateSuccess($value) { /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockBuilder $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['table']) + ->addMethods(['table']) ->getMock(); $table->setSchema([]); /** @var \Cake\ORM\Association\BelongsToMany|\PHPUnit\Framework\MockObject\MockObject $assoc */ $assoc = $this->getMockBuilder(BelongsToMany::class) - ->setMethods(['_saveTarget', 'replaceLinks']) + ->onlyMethods(['_saveTarget', 'replaceLinks']) ->setConstructorArgs(['tags', ['sourceTable' => $table]]) ->getMock(); $entity = new Entity([ @@ -1085,11 +1085,11 @@ public function testSaveAssociatedWithReplace() { /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['table']) + ->addMethods(['table']) ->getMock(); $table->setSchema([]); $assoc = $this->getMockBuilder(BelongsToMany::class) - ->setMethods(['replaceLinks']) + ->onlyMethods(['replaceLinks']) ->setConstructorArgs(['tags', ['sourceTable' => $table]]) ->getMock(); $entity = new Entity([ @@ -1116,11 +1116,11 @@ public function testSaveAssociatedWithReplaceReturnFalse() { /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['table']) + ->addMethods(['table']) ->getMock(); $table->setSchema([]); $assoc = $this->getMockBuilder(BelongsToMany::class) - ->setMethods(['replaceLinks']) + ->onlyMethods(['replaceLinks']) ->setConstructorArgs(['tags', ['sourceTable' => $table]]) ->getMock(); $entity = new Entity([ @@ -1148,7 +1148,7 @@ public function testSaveAssociatedOnlyEntitiesAppend() $connection = ConnectionManager::get('test'); /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['saveAssociated', 'schema']) + ->addMethods(['saveAssociated', 'schema']) ->setConstructorArgs([['table' => 'tags', 'connection' => $connection]]) ->getMock(); $table->setPrimaryKey('id'); diff --git a/tests/TestCase/ORM/Association/BelongsToTest.php b/tests/TestCase/ORM/Association/BelongsToTest.php index 3fe85b2229a..1155932019c 100644 --- a/tests/TestCase/ORM/Association/BelongsToTest.php +++ b/tests/TestCase/ORM/Association/BelongsToTest.php @@ -298,7 +298,7 @@ public function testCascadeDelete() public function testSaveAssociatedOnlyEntities() { $mock = $this->getMockBuilder('Cake\ORM\Table') - ->setMethods(['saveAssociated']) + ->addMethods(['saveAssociated']) ->disableOriginalConstructor() ->getMock(); $config = [ diff --git a/tests/TestCase/ORM/Association/HasManyTest.php b/tests/TestCase/ORM/Association/HasManyTest.php index 385af450451..0d83723e0b8 100644 --- a/tests/TestCase/ORM/Association/HasManyTest.php +++ b/tests/TestCase/ORM/Association/HasManyTest.php @@ -71,7 +71,7 @@ public function setUp(): void ]); $connection = ConnectionManager::get('test'); $this->article = $this->getMockBuilder('Cake\ORM\Table') - ->setMethods(['find', 'deleteAll', 'delete']) + ->onlyMethods(['find', 'deleteAll', 'delete']) ->setConstructorArgs([['alias' => 'Articles', 'table' => 'articles', 'connection' => $connection]]) ->getMock(); $this->article->setSchema([ @@ -410,7 +410,7 @@ public function testEagerLoaderMultipleKeys() $association = new HasMany('Articles', $config); $keys = [[1, 10], [2, 20], [3, 30], [4, 40]]; $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['all', 'andWhere', 'getRepository']) + ->onlyMethods(['all', 'andWhere', 'getRepository']) ->setConstructorArgs([ConnectionManager::get('test'), $this->article]) ->getMock(); $query->method('getRepository') @@ -598,7 +598,7 @@ public function testCascadeDeleteCallbacksRuleFailure() public function testSaveAssociatedOnlyEntities() { $mock = $this->getMockBuilder('Cake\ORM\Table') - ->setMethods(['saveAssociated']) + ->addMethods(['saveAssociated']) ->disableOriginalConstructor() ->getMock(); $config = [ diff --git a/tests/TestCase/ORM/Association/HasOneTest.php b/tests/TestCase/ORM/Association/HasOneTest.php index 282faac39ac..8eb16ae03e3 100644 --- a/tests/TestCase/ORM/Association/HasOneTest.php +++ b/tests/TestCase/ORM/Association/HasOneTest.php @@ -158,7 +158,7 @@ public function testAttachToMultiPrimaryKey() $association = new HasOne('Profiles', $config); $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['join', 'select']) + ->onlyMethods(['join', 'select']) ->disableOriginalConstructor() ->getMock(); $field1 = new IdentifierExpression('Profiles.user_id'); @@ -188,7 +188,7 @@ public function testAttachToMultiPrimaryKeyMismatch() $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Cannot match provided foreignKey for "Profiles", got "(user_id)" but expected foreign key for "(id, site_id)"'); $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['join', 'select']) + ->onlyMethods(['join', 'select']) ->disableOriginalConstructor() ->getMock(); $config = [ @@ -209,7 +209,7 @@ public function testAttachToMultiPrimaryKeyMismatch() public function testSaveAssociatedOnlyEntities() { $mock = $this->getMockBuilder('Cake\ORM\Table') - ->setMethods(['saveAssociated']) + ->addMethods(['saveAssociated']) ->disableOriginalConstructor() ->getMock(); $config = [ diff --git a/tests/TestCase/ORM/AssociationCollectionTest.php b/tests/TestCase/ORM/AssociationCollectionTest.php index 2c1f60f0671..515c95326a1 100644 --- a/tests/TestCase/ORM/AssociationCollectionTest.php +++ b/tests/TestCase/ORM/AssociationCollectionTest.php @@ -153,7 +153,7 @@ public function testRemoveAll() public function testGetByProperty() { $table = $this->getMockBuilder('Cake\ORM\Table') - ->setMethods(['table']) + ->addMethods(['table']) ->getMock(); $table->setSchema([]); $belongsTo = new BelongsTo('Users', [ @@ -283,17 +283,17 @@ public function testCascadeDelete() public function testSaveParents() { $table = $this->getMockBuilder('Cake\ORM\Table') - ->setMethods(['table']) + ->addMethods(['table']) ->getMock(); $table->setSchema([]); $mockOne = $this->getMockBuilder('Cake\ORM\Association\BelongsTo') - ->setMethods(['saveAssociated']) + ->onlyMethods(['saveAssociated']) ->setConstructorArgs(['Parent', [ 'sourceTable' => $table, ]]) ->getMock(); $mockTwo = $this->getMockBuilder('Cake\ORM\Association\HasMany') - ->setMethods(['saveAssociated']) + ->onlyMethods(['saveAssociated']) ->setConstructorArgs(['Child', [ 'sourceTable' => $table, ]]) @@ -333,17 +333,17 @@ public function testSaveParents() public function testSaveParentsFiltered() { $table = $this->getMockBuilder('Cake\ORM\Table') - ->setMethods(['table']) + ->addMethods(['table']) ->getMock(); $table->setSchema([]); $mockOne = $this->getMockBuilder('Cake\ORM\Association\BelongsTo') - ->setMethods(['saveAssociated']) + ->onlyMethods(['saveAssociated']) ->setConstructorArgs(['Parents', [ 'sourceTable' => $table, ]]) ->getMock(); $mockTwo = $this->getMockBuilder('Cake\ORM\Association\BelongsTo') - ->setMethods(['saveAssociated']) + ->onlyMethods(['saveAssociated']) ->setConstructorArgs(['Categories', [ 'sourceTable' => $table, ]]) @@ -383,17 +383,17 @@ public function testSaveParentsFiltered() public function testSaveChildrenFiltered() { $table = $this->getMockBuilder('Cake\ORM\Table') - ->setMethods(['table']) + ->addMethods(['table']) ->getMock(); $table->setSchema([]); $mockOne = $this->getMockBuilder('Cake\ORM\Association\HasMany') - ->setMethods(['saveAssociated']) + ->onlyMethods(['saveAssociated']) ->setConstructorArgs(['Comments', [ 'sourceTable' => $table, ]]) ->getMock(); $mockTwo = $this->getMockBuilder('Cake\ORM\Association\HasOne') - ->setMethods(['saveAssociated']) + ->onlyMethods(['saveAssociated']) ->setConstructorArgs(['Profiles', [ 'sourceTable' => $table, ]]) @@ -433,7 +433,7 @@ public function testErrorOnUnknownAlias() $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Cannot save Profiles, it is not associated to Users'); $table = $this->getMockBuilder('Cake\ORM\Table') - ->setMethods(['save']) + ->onlyMethods(['save']) ->setConstructorArgs([['alias' => 'Users']]) ->getMock(); diff --git a/tests/TestCase/ORM/AssociationProxyTest.php b/tests/TestCase/ORM/AssociationProxyTest.php index a95b0fa6a94..63513c22084 100644 --- a/tests/TestCase/ORM/AssociationProxyTest.php +++ b/tests/TestCase/ORM/AssociationProxyTest.php @@ -181,7 +181,7 @@ public function testAssociationMethodProxy() { $articles = $this->getTableLocator()->get('articles'); $mock = $this->getMockBuilder('Cake\ORM\Table') - ->setMethods(['crazy']) + ->addMethods(['crazy']) ->getMock(); $articles->belongsTo('authors', [ 'targetTable' => $mock, diff --git a/tests/TestCase/ORM/AssociationTest.php b/tests/TestCase/ORM/AssociationTest.php index 8884ef026df..0e6206d5070 100644 --- a/tests/TestCase/ORM/AssociationTest.php +++ b/tests/TestCase/ORM/AssociationTest.php @@ -56,7 +56,7 @@ public function setUp(): void 'joinType' => 'INNER', ]; $this->association = $this->getMockBuilder(Association::class) - ->setMethods([ + ->onlyMethods([ '_options', 'attachTo', '_joinCondition', 'cascadeDelete', 'isOwningSide', 'saveAssociated', 'eagerLoader', 'type', 'requiresKeys', ]) @@ -134,7 +134,7 @@ public function testSetNameToTargetAlias() public function testSetttingClassNameFromAlias() { $association = $this->getMockBuilder(Association::class) - ->setMethods(['type', 'eagerLoader', 'cascadeDelete', 'isOwningSide', 'saveAssociated']) + ->onlyMethods(['type', 'eagerLoader', 'cascadeDelete', 'isOwningSide', 'saveAssociated']) ->setConstructorArgs(['Foo']) ->getMock(); @@ -218,7 +218,7 @@ public function testClassNameUnnormalized() 'className' => 'Test', ]; $this->association = $this->getMockBuilder('Cake\ORM\Association') - ->setMethods([ + ->onlyMethods([ '_options', 'attachTo', '_joinCondition', 'cascadeDelete', 'isOwningSide', 'saveAssociated', 'eagerLoader', 'type', 'requiresKeys', ]) @@ -243,7 +243,7 @@ public function testInvalidTableFetchedFromRegistry() 'className' => TestTable::class, ]; $this->association = $this->getMockBuilder('Cake\ORM\Association') - ->setMethods([ + ->onlyMethods([ '_options', 'attachTo', '_joinCondition', 'cascadeDelete', 'isOwningSide', 'saveAssociated', 'eagerLoader', 'type', 'requiresKeys', ]) @@ -269,7 +269,7 @@ public function testTargetTableDescendant() 'className' => $className, ]; $this->association = $this->getMockBuilder('Cake\ORM\Association') - ->setMethods([ + ->onlyMethods([ '_options', 'attachTo', '_joinCondition', 'cascadeDelete', 'isOwningSide', 'saveAssociated', 'eagerLoader', 'type', 'requiresKeys', ]) @@ -407,7 +407,7 @@ public function testTargetPlugin() ]; $this->association = $this->getMockBuilder('Cake\ORM\Association') - ->setMethods([ + ->onlyMethods([ 'type', 'eagerLoader', 'cascadeDelete', 'isOwningSide', 'saveAssociated', 'requiresKeys', ]) @@ -504,7 +504,7 @@ public function testPropertyNameExplicitySet() 'propertyName' => 'foo', ]; $association = $this->getMockBuilder('Cake\ORM\Association') - ->setMethods([ + ->onlyMethods([ '_options', 'attachTo', '_joinCondition', 'cascadeDelete', 'isOwningSide', 'saveAssociated', 'eagerLoader', 'type', 'requiresKeys', ]) @@ -570,7 +570,7 @@ public function testFinderInConstructor() 'finder' => 'published', ]; $assoc = $this->getMockBuilder('Cake\ORM\Association') - ->setMethods([ + ->onlyMethods([ 'type', 'eagerLoader', 'cascadeDelete', 'isOwningSide', 'saveAssociated', 'requiresKeys', ]) @@ -607,7 +607,7 @@ public function testLocatorInConstructor() 'tableLocator' => $locator, ]; $assoc = $this->getMockBuilder('Cake\ORM\Association') - ->setMethods([ + ->onlyMethods([ 'type', 'eagerLoader', 'cascadeDelete', 'isOwningSide', 'saveAssociated', 'requiresKeys', ]) diff --git a/tests/TestCase/ORM/BehaviorRegistryTest.php b/tests/TestCase/ORM/BehaviorRegistryTest.php index cc2100e8c62..5e190f0759b 100644 --- a/tests/TestCase/ORM/BehaviorRegistryTest.php +++ b/tests/TestCase/ORM/BehaviorRegistryTest.php @@ -275,7 +275,7 @@ public function testCall() { $this->Behaviors->load('Sluggable'); $mockedBehavior = $this->getMockBuilder('Cake\ORM\Behavior') - ->setMethods(['slugify']) + ->addMethods(['slugify']) ->disableOriginalConstructor() ->getMock(); $this->Behaviors->set('Sluggable', $mockedBehavior); @@ -312,7 +312,7 @@ public function testCallFinder() { $this->Behaviors->load('Sluggable'); $mockedBehavior = $this->getMockBuilder('Cake\ORM\Behavior') - ->setMethods(['findNoSlug']) + ->addMethods(['findNoSlug']) ->disableOriginalConstructor() ->getMock(); $this->Behaviors->set('Sluggable', $mockedBehavior); diff --git a/tests/TestCase/ORM/CompositeKeysTest.php b/tests/TestCase/ORM/CompositeKeysTest.php index 504c47b9c5b..ed016677260 100644 --- a/tests/TestCase/ORM/CompositeKeysTest.php +++ b/tests/TestCase/ORM/CompositeKeysTest.php @@ -587,7 +587,7 @@ public function testFindThreadedCompositeKeys() { $table = $this->getTableLocator()->get('SiteAuthors'); $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['_addDefaultFields', 'execute']) + ->onlyMethods(['_addDefaultFields', 'execute']) ->setConstructorArgs([$table->getConnection(), $table]) ->getMock(); diff --git a/tests/TestCase/ORM/EagerLoaderTest.php b/tests/TestCase/ORM/EagerLoaderTest.php index c45409a9c29..de2ee9f3660 100644 --- a/tests/TestCase/ORM/EagerLoaderTest.php +++ b/tests/TestCase/ORM/EagerLoaderTest.php @@ -149,7 +149,7 @@ public function testContainToJoinsOneLevel() ]; $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['join']) + ->onlyMethods(['join']) ->setConstructorArgs([$this->connection, $this->table]) ->getMock(); @@ -488,7 +488,7 @@ public function testNormalizedPath() ]; $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['join']) + ->onlyMethods(['join']) ->setConstructorArgs([$this->connection, $this->table]) ->getMock(); diff --git a/tests/TestCase/ORM/EntityTest.php b/tests/TestCase/ORM/EntityTest.php index 4750b5827be..23d9bc7df6d 100644 --- a/tests/TestCase/ORM/EntityTest.php +++ b/tests/TestCase/ORM/EntityTest.php @@ -164,7 +164,7 @@ public function testExtractOriginalValues() public function testSetOneParamWithSetter() { $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['_setName']) + ->addMethods(['_setName']) ->getMock(); $entity->expects($this->once())->method('_setName') ->with('Jones') @@ -185,7 +185,7 @@ public function testSetOneParamWithSetter() public function testMultipleWithSetter() { $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['_setName', '_setStuff']) + ->addMethods(['_setName', '_setStuff']) ->getMock(); $entity->setAccess('*', true); $entity->expects($this->once())->method('_setName') @@ -215,7 +215,7 @@ public function testMultipleWithSetter() public function testBypassSetters() { $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['_setName', '_setStuff']) + ->addMethods(['_setName', '_setStuff']) ->getMock(); $entity->setAccess('*', true); @@ -240,7 +240,7 @@ public function testBypassSetters() public function testConstructor() { $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['set']) + ->onlyMethods(['set']) ->disableOriginalConstructor() ->getMock(); $entity->expects($this->at(0)) @@ -264,7 +264,7 @@ public function testConstructor() public function testConstructorWithGuard() { $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['set']) + ->onlyMethods(['set']) ->disableOriginalConstructor() ->getMock(); $entity->expects($this->once()) @@ -293,7 +293,7 @@ public function testGetNoGetters() public function testGetCustomGetters() { $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['_getName']) + ->addMethods(['_getName']) ->getMock(); $entity->expects($this->any()) ->method('_getName') @@ -314,7 +314,7 @@ public function testGetCustomGetters() public function testGetCustomGettersAfterSet() { $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['_getName']) + ->addMethods(['_getName']) ->getMock(); $entity->expects($this->any()) ->method('_getName') @@ -339,7 +339,7 @@ public function testGetCacheClearedByUnset() { /** @var \Cake\ORM\Entity|\PHPUnit\Framework\MockObject\MockObject $entity */ $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['_getName']) + ->addMethods(['_getName']) ->getMock(); $entity->expects($this->any())->method('_getName') ->will($this->returnCallback(function ($name) { @@ -360,7 +360,7 @@ public function testGetCacheClearedByUnset() public function testGetCamelCasedProperties() { $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['_getListIdName']) + ->addMethods(['_getListIdName']) ->getMock(); $entity->expects($this->any())->method('_getListIdName') ->will($this->returnCallback(function ($name) { @@ -393,7 +393,7 @@ public function testMagicSet() public function testMagicSetWithSetter() { $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['_setName']) + ->addMethods(['_setName']) ->getMock(); $entity->expects($this->once())->method('_setName') ->with('Jones') @@ -414,7 +414,7 @@ public function testMagicSetWithSetter() public function testMagicSetWithSetterTitleCase() { $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['_setName']) + ->addMethods(['_setName']) ->getMock(); $entity->expects($this->once()) ->method('_setName') @@ -436,7 +436,7 @@ public function testMagicSetWithSetterTitleCase() public function testMagicGetWithGetter() { $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['_getName']) + ->addMethods(['_getName']) ->getMock(); $entity->expects($this->once())->method('_getName') ->with('Jones') @@ -457,7 +457,7 @@ public function testMagicGetWithGetter() public function testMagicGetWithGetterTitleCase() { $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['_getName']) + ->addMethods(['_getName']) ->getMock(); $entity->expects($this->once()) ->method('_getName') @@ -503,7 +503,7 @@ public function testHas() $this->assertFalse($entity->has(['id', 'nope'])); $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['_getThings']) + ->addMethods(['_getThings']) ->getMock(); $entity->expects($this->once())->method('_getThings') ->will($this->returnValue(0)); @@ -574,7 +574,7 @@ public function testMagicIsset() public function testMagicUnset() { $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['unset']) + ->onlyMethods(['unset']) ->getMock(); $entity->expects($this->at(0)) ->method('unset') @@ -618,7 +618,7 @@ public function testIssetArrayAccess() public function testGetArrayAccess() { $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['get']) + ->onlyMethods(['get']) ->getMock(); $entity->expects($this->at(0)) ->method('get') @@ -642,7 +642,7 @@ public function testGetArrayAccess() public function testSetArrayAccess() { $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['set']) + ->onlyMethods(['set']) ->getMock(); $entity->setAccess('*', true); @@ -669,7 +669,7 @@ public function testUnsetArrayAccess() { /** @var \Cake\ORM\Entity|\PHPUnit\Framework\MockObject\MockObject $entity */ $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['unset']) + ->onlyMethods(['unset']) ->getMock(); $entity->expects($this->at(0)) ->method('unset') @@ -688,11 +688,11 @@ public function testMethodCache() { /** @var \Cake\ORM\Entity|\PHPUnit\Framework\MockObject\MockObject $entity */ $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['_setFoo', '_getBar']) + ->addMethods(['_setFoo', '_getBar']) ->getMock(); /** @var \Cake\ORM\Entity|\PHPUnit\Framework\MockObject\MockObject $entity2 */ $entity2 = $this->getMockBuilder(Entity::class) - ->setMethods(['_setBar']) + ->addMethods(['_setBar']) ->getMock(); $entity->expects($this->once())->method('_setFoo'); $entity->expects($this->once())->method('_getBar'); @@ -712,7 +712,7 @@ public function testSetGetLongPropertyNames() { /** @var \Cake\ORM\Entity|\PHPUnit\Framework\MockObject\MockObject $entity */ $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['_getVeryLongProperty', '_setVeryLongProperty']) + ->addMethods(['_getVeryLongProperty', '_setVeryLongProperty']) ->getMock(); $entity->expects($this->once())->method('_getVeryLongProperty'); $entity->expects($this->once())->method('_setVeryLongProperty'); @@ -754,7 +754,7 @@ public function testPhpSerialize() public function testJsonSerializeRecursive() { $phone = $this->getMockBuilder(Entity::class) - ->setMethods(['jsonSerialize']) + ->onlyMethods(['jsonSerialize']) ->getMock(); $phone->expects($this->once())->method('jsonSerialize')->will($this->returnValue(['something'])); $data = ['name' => 'James', 'age' => 20, 'phone' => $phone]; @@ -957,14 +957,14 @@ public function testIsNew() public function testConstructorWithClean() { $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['clean']) + ->onlyMethods(['clean']) ->disableOriginalConstructor() ->getMock(); $entity->expects($this->never())->method('clean'); $entity->__construct(['a' => 'b', 'c' => 'd']); $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['clean']) + ->onlyMethods(['clean']) ->disableOriginalConstructor() ->getMock(); $entity->expects($this->once())->method('clean'); @@ -979,14 +979,14 @@ public function testConstructorWithClean() public function testConstructorWithMarkNew() { $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['setNew', 'clean']) + ->onlyMethods(['setNew', 'clean']) ->disableOriginalConstructor() ->getMock(); $entity->expects($this->never())->method('clean'); $entity->__construct(['a' => 'b', 'c' => 'd']); $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['setNew']) + ->onlyMethods(['setNew']) ->disableOriginalConstructor() ->getMock(); $entity->expects($this->once())->method('setNew'); @@ -1069,7 +1069,7 @@ public function testToArrayWithAccessor() { /** @var \Cake\ORM\Entity|\PHPUnit\Framework\MockObject\MockObject $entity */ $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['_getName']) + ->addMethods(['_getName']) ->getMock(); $entity->setAccess('*', true); $entity->set(['name' => 'Mark', 'email' => 'mark@example.com']); @@ -1147,7 +1147,7 @@ public function testToArrayVirtualProperties() { /** @var \Cake\ORM\Entity|\PHPUnit\Framework\MockObject\MockObject $entity */ $entity = $this->getMockBuilder(Entity::class) - ->setMethods(['_getName']) + ->addMethods(['_getName']) ->getMock(); $entity->setAccess('*', true); diff --git a/tests/TestCase/ORM/QueryTest.php b/tests/TestCase/ORM/QueryTest.php index 8b900319beb..f5adb5683fb 100644 --- a/tests/TestCase/ORM/QueryTest.php +++ b/tests/TestCase/ORM/QueryTest.php @@ -1885,7 +1885,7 @@ public function testClearContain() { /** @var \Cake\ORM\Query $query */ $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['all']) + ->onlyMethods(['all']) ->setConstructorArgs([$this->connection, $this->table]) ->getMock(); @@ -1914,7 +1914,7 @@ public function testClearContain() public function testCollectionProxy($method, $arg, $return) { $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['all']) + ->onlyMethods(['all']) ->setConstructorArgs([$this->connection, $this->table]) ->getMock(); $query->select(); @@ -1967,7 +1967,7 @@ public function testCacheErrorOnNonSelect() public function testCacheReadIntegration() { $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->setConstructorArgs([$this->connection, $this->table]) ->getMock(); $resultSet = $this->getMockBuilder('Cake\ORM\ResultSet') @@ -2302,7 +2302,7 @@ public function testCountCache() { $query = $this->getMockBuilder('Cake\ORM\Query') ->disableOriginalConstructor() - ->setMethods(['_performCount']) + ->onlyMethods(['_performCount']) ->getMock(); $query->expects($this->once()) @@ -2326,7 +2326,7 @@ public function testCountCacheDirty() { $query = $this->getMockBuilder('Cake\ORM\Query') ->disableOriginalConstructor() - ->setMethods(['_performCount']) + ->onlyMethods(['_performCount']) ->getMock(); $query->expects($this->at(0)) diff --git a/tests/TestCase/ORM/Rule/LinkConstraintTest.php b/tests/TestCase/ORM/Rule/LinkConstraintTest.php index b9e88de9807..e13f417121c 100644 --- a/tests/TestCase/ORM/Rule/LinkConstraintTest.php +++ b/tests/TestCase/ORM/Rule/LinkConstraintTest.php @@ -194,7 +194,7 @@ public function testNonMatchingKeyFields(): void $ruleMock = $this ->getMockBuilder(LinkConstraint::class) ->setConstructorArgs(['Comments', LinkConstraint::STATUS_NOT_LINKED]) - ->setMethods(['_aliasFields']) + ->onlyMethods(['_aliasFields']) ->getMock(); $ruleMock ->expects($this->once()) diff --git a/tests/TestCase/ORM/TableTest.php b/tests/TestCase/ORM/TableTest.php index 214ea7db58d..c7c5f352311 100644 --- a/tests/TestCase/ORM/TableTest.php +++ b/tests/TestCase/ORM/TableTest.php @@ -206,7 +206,7 @@ public function testTableMethod() /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['find']) + ->onlyMethods(['find']) ->setMockClassName('SpecialThingsTable') ->getMock(); $this->assertSame('special_things', $table->getTable()); @@ -239,7 +239,7 @@ public function testSetAlias() /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['find']) + ->onlyMethods(['find']) ->setMockClassName('SpecialThingTable') ->getMock(); $this->assertSame('SpecialThing', $table->getAlias()); @@ -435,7 +435,7 @@ public function testSchemaInitialize() { $schema = $this->connection->getSchemaCollection()->describe('users'); $table = $this->getMockBuilder(Table::class) - ->setMethods(['_initializeSchema']) + ->onlyMethods(['_initializeSchema']) ->setConstructorArgs([['table' => 'users', 'connection' => $this->connection]]) ->getMock(); $table->expects($this->once()) @@ -1033,11 +1033,11 @@ public function testUpdateAllFailure() { $this->expectException(\Cake\Database\Exception::class); $table = $this->getMockBuilder(Table::class) - ->setMethods(['query']) + ->onlyMethods(['query']) ->setConstructorArgs([['table' => 'users', 'connection' => $this->connection]]) ->getMock(); $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->setConstructorArgs([$this->connection, $table]) ->getMock(); $table->expects($this->once()) @@ -1097,11 +1097,11 @@ public function testDeleteAllFailure() { $this->expectException(\Cake\Database\Exception::class); $table = $this->getMockBuilder(Table::class) - ->setMethods(['query']) + ->onlyMethods(['query']) ->setConstructorArgs([['table' => 'users', 'connection' => $this->connection]]) ->getMock(); $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->setConstructorArgs([$this->connection, $table]) ->getMock(); $table->expects($this->once()) @@ -1123,7 +1123,7 @@ public function testDeleteAllFailure() public function testFindApplyOptions() { $table = $this->getMockBuilder(Table::class) - ->setMethods(['query', 'findAll']) + ->onlyMethods(['query', 'findAll']) ->setConstructorArgs([['table' => 'users', 'connection' => $this->connection]]) ->getMock(); $query = $this->getMockBuilder('Cake\ORM\Query') @@ -1281,12 +1281,12 @@ public function testFindThreadedNoHydration() public function testStackingFinders() { $table = $this->getMockBuilder(Table::class) - ->setMethods(['find', 'findList']) + ->onlyMethods(['find', 'findList']) ->disableOriginalConstructor() ->getMock(); $params = [$this->connection, $table]; $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['addDefaultTypes']) + ->onlyMethods(['addDefaultTypes']) ->setConstructorArgs($params) ->getMock(); @@ -1914,7 +1914,7 @@ public function testImplementedEvents() { /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods([ + ->addMethods([ 'buildValidator', 'beforeMarshal', 'beforeFind', @@ -1984,7 +1984,7 @@ public function testSaveNewEntityNoExists() { /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['exists']) + ->onlyMethods(['exists']) ->setConstructorArgs([[ 'connection' => $this->connection, 'alias' => 'Users', @@ -2010,7 +2010,7 @@ public function testSavePrimaryKeyEntityExists() $this->skipIfSqlServer(); /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['exists']) + ->onlyMethods(['exists']) ->setConstructorArgs([[ 'connection' => $this->connection, 'alias' => 'Users', @@ -2035,7 +2035,7 @@ public function testSavePrimaryKeyEntityNoExists() $this->skipIfSqlServer(); /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['exists']) + ->onlyMethods(['exists']) ->setConstructorArgs([[ 'connection' => $this->connection, 'alias' => 'Users', @@ -2332,11 +2332,11 @@ public function testAfterSaveNotCalled() { /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['query']) + ->onlyMethods(['query']) ->setConstructorArgs([['table' => 'users', 'connection' => $this->connection]]) ->getMock(); $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['execute', 'addDefaultTypes']) + ->onlyMethods(['execute', 'addDefaultTypes']) ->setConstructorArgs([$this->connection, $table]) ->getMock(); $statement = $this->getMockBuilder(StatementInterface::class)->getMock(); @@ -2441,14 +2441,14 @@ public function testAtomicSave() $config = ConnectionManager::getConfig('test'); $connection = $this->getMockBuilder('Cake\Database\Connection') - ->setMethods(['begin', 'commit', 'inTransaction']) + ->onlyMethods(['begin', 'commit', 'inTransaction']) ->setConstructorArgs([$config]) ->getMock(); $connection->setDriver($this->connection->getDriver()); /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['getConnection']) + ->onlyMethods(['getConnection']) ->setConstructorArgs([['table' => 'users']]) ->getMock(); $table->expects($this->any())->method('getConnection') @@ -2475,17 +2475,17 @@ public function testAtomicSaveRollback() { $this->expectException(\PDOException::class); $connection = $this->getMockBuilder('Cake\Database\Connection') - ->setMethods(['begin', 'rollback']) + ->onlyMethods(['begin', 'rollback']) ->setConstructorArgs([ConnectionManager::getConfig('test')]) ->getMock(); $connection->setDriver(ConnectionManager::get('test')->getDriver()); /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['query', 'getConnection']) + ->onlyMethods(['query', 'getConnection']) ->setConstructorArgs([['table' => 'users']]) ->getMock(); $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['execute', 'addDefaultTypes']) + ->onlyMethods(['execute', 'addDefaultTypes']) ->setConstructorArgs([$connection, $table]) ->getMock(); $table->expects($this->any())->method('getConnection') @@ -2516,17 +2516,17 @@ public function testAtomicSaveRollback() public function testAtomicSaveRollbackOnFailure() { $connection = $this->getMockBuilder('Cake\Database\Connection') - ->setMethods(['begin', 'rollback']) + ->onlyMethods(['begin', 'rollback']) ->setConstructorArgs([ConnectionManager::getConfig('test')]) ->getMock(); $connection->setDriver(ConnectionManager::get('test')->getDriver()); /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['query', 'getConnection', 'exists']) + ->onlyMethods(['query', 'getConnection', 'exists']) ->setConstructorArgs([['table' => 'users']]) ->getMock(); $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['execute', 'addDefaultTypes']) + ->onlyMethods(['execute', 'addDefaultTypes']) ->setConstructorArgs([$connection, $table]) ->getMock(); @@ -2684,7 +2684,7 @@ public function testSaveUpdateWithHint() { /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['exists']) + ->onlyMethods(['exists']) ->setConstructorArgs([['table' => 'users', 'connection' => ConnectionManager::get('test')]]) ->getMock(); $entity = new Entity([ @@ -2707,12 +2707,12 @@ public function testSaveUpdatePrimaryKeyNotModified() { /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['query']) + ->onlyMethods(['query']) ->setConstructorArgs([['table' => 'users', 'connection' => $this->connection]]) ->getMock(); $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['execute', 'addDefaultTypes', 'set']) + ->onlyMethods(['execute', 'addDefaultTypes', 'set']) ->setConstructorArgs([$this->connection, $table]) ->getMock(); @@ -2750,7 +2750,7 @@ public function testUpdateNoChange() { /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['query']) + ->onlyMethods(['query']) ->setConstructorArgs([['table' => 'users', 'connection' => $this->connection]]) ->getMock(); $table->expects($this->never())->method('query'); @@ -2789,7 +2789,7 @@ public function testUpdateNoPrimaryButOtherKeys() $this->expectException(\InvalidArgumentException::class); /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['query']) + ->onlyMethods(['query']) ->setConstructorArgs([['table' => 'users', 'connection' => $this->connection]]) ->getMock(); $table->expects($this->never())->method('query'); @@ -3375,7 +3375,7 @@ public function testDeleteIsNew() /** @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject $table */ $table = $this->getMockBuilder(Table::class) - ->setMethods(['query']) + ->onlyMethods(['query']) ->setConstructorArgs([['connection' => $this->connection]]) ->getMock(); $table->expects($this->never()) @@ -3473,7 +3473,7 @@ public function testValidatorBehavior() public function testValidationWithDefiner() { $table = $this->getMockBuilder(Table::class) - ->setMethods(['validationForOtherStuff']) + ->addMethods(['validationForOtherStuff']) ->getMock(); $table->expects($this->once())->method('validationForOtherStuff') ->will($this->returnArgument(0)); @@ -3491,7 +3491,7 @@ public function testValidationWithDefiner() public function testValidationWithBadDefiner() { $table = $this->getMockBuilder(Table::class) - ->setMethods(['validationBad']) + ->addMethods(['validationBad']) ->getMock(); $table->expects($this->once()) ->method('validationBad'); @@ -4191,7 +4191,7 @@ public function testSaveWithOptionBuilder() public function testSaveCleanEntity() { $table = $this->getMockBuilder(Table::class) - ->setMethods(['_processSave']) + ->onlyMethods(['_processSave']) ->getMock(); $entity = new Entity( ['id' => 'foo'], @@ -4235,15 +4235,16 @@ public function testBelongsToManyIntegration() public function testSaveDeepAssociationOptions() { $articles = $this->getMockBuilder(Table::class) - ->setMethods(['_insert']) + ->onlyMethods(['_insert']) ->setConstructorArgs([['table' => 'articles', 'connection' => $this->connection]]) ->getMock(); $authors = $this->getMockBuilder(Table::class) - ->setMethods(['_insert']) + ->onlyMethods(['_insert']) ->setConstructorArgs([['table' => 'authors', 'connection' => $this->connection]]) ->getMock(); $supervisors = $this->getMockBuilder(Table::class) - ->setMethods(['_insert', 'validate']) + ->onlyMethods(['_insert']) + ->addMethods(['validate']) ->setConstructorArgs([[ 'table' => 'authors', 'alias' => 'supervisors', @@ -4251,7 +4252,7 @@ public function testSaveDeepAssociationOptions() ]]) ->getMock(); $tags = $this->getMockBuilder(Table::class) - ->setMethods(['_insert']) + ->onlyMethods(['_insert']) ->setConstructorArgs([['table' => 'tags', 'connection' => $this->connection]]) ->getMock(); @@ -4309,11 +4310,11 @@ public function testBelongsToFluentInterface() { /** @var \TestApp\Model\Table\ArticlesTable $articles */ $articles = $this->getMockBuilder(Table::class) - ->setMethods(['_insert']) + ->onlyMethods(['_insert']) ->setConstructorArgs([['table' => 'articles', 'connection' => $this->connection]]) ->getMock(); $authors = $this->getMockBuilder(Table::class) - ->setMethods(['_insert']) + ->onlyMethods(['_insert']) ->setConstructorArgs([['table' => 'authors', 'connection' => $this->connection]]) ->getMock(); @@ -4340,7 +4341,7 @@ public function testHasOneFluentInterface() { /** @var \TestApp\Model\Table\AuthorsTable $authors */ $authors = $this->getMockBuilder(Table::class) - ->setMethods(['_insert']) + ->onlyMethods(['_insert']) ->setConstructorArgs([['table' => 'authors', 'connection' => $this->connection]]) ->getMock(); @@ -4369,7 +4370,7 @@ public function testHasManyFluentInterface() { /** @var \TestApp\Model\Table\AuthorsTable $authors */ $authors = $this->getMockBuilder(Table::class) - ->setMethods(['_insert']) + ->onlyMethods(['_insert']) ->setConstructorArgs([['table' => 'authors', 'connection' => $this->connection]]) ->getMock(); @@ -4400,7 +4401,7 @@ public function testBelongsToManyFluentInterface() { /** @var \TestApp\Model\Table\AuthorsTable $authors */ $authors = $this->getMockBuilder(Table::class) - ->setMethods(['_insert']) + ->onlyMethods(['_insert']) ->setConstructorArgs([['table' => 'authors', 'connection' => $this->connection]]) ->getMock(); try { @@ -4734,7 +4735,7 @@ public function testUnlinkHasManyEmpty() public function testReplaceHasManyOnErrorDependentCascadeCallbacks() { $articles = $this->getMockBuilder(Table::class) - ->setMethods(['delete']) + ->onlyMethods(['delete']) ->setConstructorArgs([[ 'connection' => $this->connection, 'alias' => 'Articles', @@ -4747,7 +4748,7 @@ public function testReplaceHasManyOnErrorDependentCascadeCallbacks() $associations = new AssociationCollection(); $hasManyArticles = $this->getMockBuilder('Cake\ORM\Association\HasMany') - ->setMethods(['getTarget']) + ->onlyMethods(['getTarget']) ->setConstructorArgs([ 'articles', [ @@ -5525,7 +5526,7 @@ function (EventInterface $event, EntityInterface $entity, ArrayObject $options) public function testSimplifiedFind() { $table = $this->getMockBuilder(Table::class) - ->setMethods(['callFinder']) + ->onlyMethods(['callFinder']) ->setConstructorArgs([[ 'connection' => $this->connection, 'schema' => ['id' => ['type' => 'integer']], @@ -5557,7 +5558,7 @@ public function providerForTestGet() public function testGet($options) { $table = $this->getMockBuilder(Table::class) - ->setMethods(['callFinder', 'query']) + ->onlyMethods(['callFinder', 'query']) ->setConstructorArgs([[ 'connection' => $this->connection, 'schema' => [ @@ -5569,7 +5570,7 @@ public function testGet($options) ->getMock(); $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['addDefaultTypes', 'firstOrFail', 'where', 'cache']) + ->onlyMethods(['addDefaultTypes', 'firstOrFail', 'where', 'cache']) ->setConstructorArgs([$this->connection, $table]) ->getMock(); @@ -5607,7 +5608,7 @@ public function providerForTestGetWithCustomFinder() public function testGetWithCustomFinder($options) { $table = $this->getMockBuilder(Table::class) - ->setMethods(['callFinder', 'query']) + ->onlyMethods(['callFinder', 'query']) ->setConstructorArgs([[ 'connection' => $this->connection, 'schema' => [ @@ -5619,7 +5620,7 @@ public function testGetWithCustomFinder($options) ->getMock(); $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['addDefaultTypes', 'firstOrFail', 'where', 'cache']) + ->onlyMethods(['addDefaultTypes', 'firstOrFail', 'where', 'cache']) ->setConstructorArgs([$this->connection, $table]) ->getMock(); @@ -5666,7 +5667,7 @@ public function providerForTestGetWithCache() public function testGetWithCache($options, $cacheKey, $cacheConfig) { $table = $this->getMockBuilder(Table::class) - ->setMethods(['callFinder', 'query']) + ->onlyMethods(['callFinder', 'query']) ->setConstructorArgs([[ 'connection' => $this->connection, 'schema' => [ @@ -5679,7 +5680,7 @@ public function testGetWithCache($options, $cacheKey, $cacheConfig) $table->setTable('table_name'); $query = $this->getMockBuilder('Cake\ORM\Query') - ->setMethods(['addDefaultTypes', 'firstOrFail', 'where', 'cache']) + ->onlyMethods(['addDefaultTypes', 'firstOrFail', 'where', 'cache']) ->setConstructorArgs([$this->connection, $table]) ->getMock(); @@ -5762,7 +5763,7 @@ public function testGetExceptionOnTooMuchData() public function testPatchEntityMarshallerUsage() { $table = $this->getMockBuilder(Table::class) - ->setMethods(['marshaller']) + ->onlyMethods(['marshaller']) ->getMock(); $marshaller = $this->getMockBuilder('Cake\ORM\Marshaller') ->setConstructorArgs([$table]) @@ -5807,7 +5808,7 @@ public function testPatchEntity() public function testPatchEntitiesMarshallerUsage() { $table = $this->getMockBuilder(Table::class) - ->setMethods(['marshaller']) + ->onlyMethods(['marshaller']) ->getMock(); $marshaller = $this->getMockBuilder('Cake\ORM\Marshaller') ->setConstructorArgs([$table]) diff --git a/tests/TestCase/Routing/Middleware/RoutingMiddlewareTest.php b/tests/TestCase/Routing/Middleware/RoutingMiddlewareTest.php index 16d09d5092f..12d215710ea 100644 --- a/tests/TestCase/Routing/Middleware/RoutingMiddlewareTest.php +++ b/tests/TestCase/Routing/Middleware/RoutingMiddlewareTest.php @@ -186,7 +186,7 @@ public function testRoutesHookCallsPluginHook() $request = ServerRequestFactory::fromGlobals(['REQUEST_URI' => '/app/articles']); $app = $this->getMockBuilder(Application::class) - ->setMethods(['pluginRoutes']) + ->onlyMethods(['pluginRoutes']) ->setConstructorArgs([CONFIG]) ->getMock(); $app->expects($this->once()) diff --git a/tests/TestCase/Routing/Route/RouteTest.php b/tests/TestCase/Routing/Route/RouteTest.php index 7036651ffaa..93651fb664b 100644 --- a/tests/TestCase/Routing/Route/RouteTest.php +++ b/tests/TestCase/Routing/Route/RouteTest.php @@ -1096,7 +1096,7 @@ public function testParseRequestDelegates() { /** @var \Cake\Routing\Route\Route|\PHPUnit\Framework\MockObject\MockObject $route */ $route = $this->getMockBuilder('Cake\Routing\Route\Route') - ->setMethods(['parse']) + ->onlyMethods(['parse']) ->setConstructorArgs(['/forward', ['controller' => 'Articles', 'action' => 'index']]) ->getMock(); diff --git a/tests/TestCase/Routing/RouteCollectionTest.php b/tests/TestCase/Routing/RouteCollectionTest.php index b372690d209..01246a26de4 100644 --- a/tests/TestCase/Routing/RouteCollectionTest.php +++ b/tests/TestCase/Routing/RouteCollectionTest.php @@ -693,7 +693,7 @@ public function testRegisterMiddleware() $this->assertSame($result, $this->collection); $mock = $this->getMockBuilder('\stdClass') - ->setMethods(['__invoke']) + ->addMethods(['__invoke']) ->getMock(); $result = $this->collection->registerMiddleware('callable', $mock); $this->assertSame($result, $this->collection); @@ -715,7 +715,7 @@ public function testMiddlewareGroup() }); $mock = $this->getMockBuilder('\stdClass') - ->setMethods(['__invoke']) + ->addMethods(['__invoke']) ->getMock(); $result = $this->collection->registerMiddleware('callable', $mock); $this->collection->registerMiddleware('callable', $mock); diff --git a/tests/TestCase/Routing/RouterTest.php b/tests/TestCase/Routing/RouterTest.php index 9d3ea266183..2b0d71cc1a8 100644 --- a/tests/TestCase/Routing/RouterTest.php +++ b/tests/TestCase/Routing/RouterTest.php @@ -2751,7 +2751,7 @@ public function testUrlFullUrlReturnFromRoute() $url = 'http://example.com/posts/view/1'; $route = $this->getMockBuilder('Cake\Routing\Route\Route') - ->setMethods(['match']) + ->onlyMethods(['match']) ->setConstructorArgs(['/:controller/:action/*']) ->getMock(); $route->expects($this->any()) diff --git a/tests/TestCase/TestSuite/FixtureManagerTest.php b/tests/TestCase/TestSuite/FixtureManagerTest.php index b88923d3cb6..14e4e7bdeb7 100644 --- a/tests/TestCase/TestSuite/FixtureManagerTest.php +++ b/tests/TestCase/TestSuite/FixtureManagerTest.php @@ -297,7 +297,7 @@ public function testLoadConnectionAliasUsage() // This connection should _not_ be used. $other = $this->getMockBuilder('Cake\Database\Connection') - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->setConstructorArgs([['driver' => $connection->getDriver()]]) ->getMock(); $other->expects($this->never()) @@ -307,7 +307,7 @@ public function testLoadConnectionAliasUsage() // This connection should be used instead of // the 'other' connection as the alias should not be ignored. $testOther = $this->getMockBuilder('Cake\Database\Connection') - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->setConstructorArgs([[ 'database' => $connection->config()['database'], 'driver' => $connection->getDriver(), @@ -342,7 +342,7 @@ public function testLoadConnectionAliasUsage() public function testLoadSingle() { $test = $this->getMockBuilder('Cake\TestSuite\TestCase') - ->setMethods(['getFixtures']) + ->onlyMethods(['getFixtures']) ->getMock(); $test->autoFixtures = false; $test->expects($this->any()) @@ -381,7 +381,7 @@ public function testExceptionOnLoad() ->willReturn(['core.Products']); $manager = $this->getMockBuilder(FixtureManager::class) - ->setMethods(['_runOperation']) + ->onlyMethods(['_runOperation']) ->getMock(); $manager->expects($this->any()) ->method('_runOperation') @@ -411,7 +411,7 @@ public function testExceptionOnLoad() public function testExceptionOnLoadFixture($method, $expectedMessage) { $fixture = $this->getMockBuilder('Cake\Test\Fixture\ProductsFixture') - ->setMethods([$method]) + ->onlyMethods([$method]) ->getMock(); $fixture->expects($this->once()) ->method($method) @@ -430,7 +430,7 @@ public function testExceptionOnLoadFixture($method, $expectedMessage) /** @var \Cake\TestSuite\Fixture\FixtureManager|\PHPUnit\Framework\MockObject\MockObject $manager */ $manager = $this->getMockBuilder(FixtureManager::class) - ->setMethods(['_fixtureConnections']) + ->onlyMethods(['_fixtureConnections']) ->getMock(); $manager->expects($this->any()) ->method('_fixtureConnections') diff --git a/tests/TestCase/TestSuite/TestFixtureTest.php b/tests/TestCase/TestSuite/TestFixtureTest.php index b5d59bcedb6..ea5c1a863af 100644 --- a/tests/TestCase/TestSuite/TestFixtureTest.php +++ b/tests/TestCase/TestSuite/TestFixtureTest.php @@ -178,7 +178,7 @@ public function testInitNoImportNoFields() $this->assertSame(['id', 'letter'], $fixture->getTableSchema()->columns()); $db = $this->getMockBuilder('Cake\Database\Connection') - ->setMethods(['prepare', 'execute']) + ->onlyMethods(['prepare', 'execute']) ->disableOriginalConstructor() ->getMock(); $db->expects($this->never()) diff --git a/tests/TestCase/TestSuite/TestSuiteTest.php b/tests/TestCase/TestSuite/TestSuiteTest.php index f17d6183208..abcf6eeaa00 100644 --- a/tests/TestCase/TestSuite/TestSuiteTest.php +++ b/tests/TestCase/TestSuite/TestSuiteTest.php @@ -35,7 +35,7 @@ public function testAddTestDirectory() $count = count(glob($testFolder . DS . '*Test.php')); $suite = $this->getMockBuilder('Cake\TestSuite\TestSuite') - ->setMethods(['addTestFile']) + ->onlyMethods(['addTestFile']) ->getMock(); $suite ->expects($this->exactly($count)) @@ -56,7 +56,7 @@ public function testAddTestDirectoryRecursive() $count += count(glob($testFolder . DS . 'Engine/*Test.php')); $suite = $this->getMockBuilder('Cake\TestSuite\TestSuite') - ->setMethods(['addTestFile']) + ->onlyMethods(['addTestFile']) ->getMock(); $suite ->expects($this->exactly($count)) @@ -83,7 +83,7 @@ public function testAddTestDirectoryRecursiveWithHidden() touch($path . DS . '.HiddenTest.php'); $suite = $this->getMockBuilder('Cake\TestSuite\TestSuite') - ->setMethods(['addTestFile']) + ->onlyMethods(['addTestFile']) ->getMock(); $suite ->expects($this->exactly(1)) @@ -111,7 +111,7 @@ public function testAddTestDirectoryRecursiveWithNonPhp() touch($path . DS . 'NotHiddenTest.php'); $suite = $this->getMockBuilder('Cake\TestSuite\TestSuite') - ->setMethods(['addTestFile']) + ->onlyMethods(['addTestFile']) ->getMock(); $suite ->expects($this->exactly(1)) diff --git a/tests/TestCase/Validation/ValidatorTest.php b/tests/TestCase/Validation/ValidatorTest.php index 9581184a5dd..d9783f4bfc2 100644 --- a/tests/TestCase/Validation/ValidatorTest.php +++ b/tests/TestCase/Validation/ValidatorTest.php @@ -1828,7 +1828,7 @@ public function testErrorsFromCustomProvider() ->add('title', 'cool', ['rule' => 'isCool', 'provider' => 'thing']); $thing = $this->getMockBuilder('\stdClass') - ->setMethods(['isCool']) + ->addMethods(['isCool']) ->getMock(); $thing->expects($this->once())->method('isCool') ->will($this->returnCallback(function ($data, $context) use ($thing) { @@ -1874,7 +1874,7 @@ public function testMethodsWithExtraArguments() 'provider' => 'thing', ]); $thing = $this->getMockBuilder('\stdClass') - ->setMethods(['isCool']) + ->addMethods(['isCool']) ->getMock(); $thing->expects($this->once())->method('isCool') ->will($this->returnCallback(function ($data, $a, $b, $context) use ($thing) { diff --git a/tests/TestCase/View/Helper/HtmlHelperTest.php b/tests/TestCase/View/Helper/HtmlHelperTest.php index d2d7adc3519..f24b4dd2234 100644 --- a/tests/TestCase/View/Helper/HtmlHelperTest.php +++ b/tests/TestCase/View/Helper/HtmlHelperTest.php @@ -76,7 +76,7 @@ public function setUp(): void Router::setRequest($request); $this->View = $this->getMockBuilder(View::class) - ->setMethods(['append']) + ->onlyMethods(['append']) ->setConstructorArgs([$request]) ->getMock(); $this->Html = new HtmlHelper($this->View); diff --git a/tests/TestCase/View/Helper/NumberHelperTest.php b/tests/TestCase/View/Helper/NumberHelperTest.php index 303aeb2ca51..ceb4ac1cc6e 100644 --- a/tests/TestCase/View/Helper/NumberHelperTest.php +++ b/tests/TestCase/View/Helper/NumberHelperTest.php @@ -94,7 +94,7 @@ public function methodProvider() public function testNumberHelperProxyMethodCalls($method) { $number = $this->getMockBuilder(NumberMock::class) - ->setMethods([$method]) + ->addMethods([$method]) ->getMock(); $helper = new NumberHelperTestObject($this->View, ['engine' => NumberMock::class]); $helper->attach($number); diff --git a/tests/TestCase/View/Helper/TextHelperTest.php b/tests/TestCase/View/Helper/TextHelperTest.php index 7f6cb93b51c..6a1e5b387cb 100644 --- a/tests/TestCase/View/Helper/TextHelperTest.php +++ b/tests/TestCase/View/Helper/TextHelperTest.php @@ -78,7 +78,7 @@ public function testTextHelperProxyMethodCalls() 'stripLinks', 'toList', ]; $String = $this->getMockBuilder(TextMock::class) - ->setMethods($methods) + ->addMethods($methods) ->getMock(); $Text = new TextHelperTestObject($this->View, ['engine' => TextMock::class]); $Text->attach($String); @@ -91,7 +91,7 @@ public function testTextHelperProxyMethodCalls() 'excerpt', ]; $String = $this->getMockBuilder(TextMock::class) - ->setMethods($methods) + ->addMethods($methods) ->getMock(); $Text = new TextHelperTestObject($this->View, ['engine' => TextMock::class]); $Text->attach($String); @@ -104,7 +104,7 @@ public function testTextHelperProxyMethodCalls() 'highlight', ]; $String = $this->getMockBuilder(TextMock::class) - ->setMethods($methods) + ->addMethods($methods) ->getMock(); $Text = new TextHelperTestObject($this->View, ['engine' => TextMock::class]); $Text->attach($String); @@ -117,7 +117,7 @@ public function testTextHelperProxyMethodCalls() 'tail', 'truncate', ]; $String = $this->getMockBuilder(TextMock::class) - ->setMethods($methods) + ->addMethods($methods) ->getMock(); $Text = new TextHelperTestObject($this->View, ['engine' => TextMock::class]); $Text->attach($String); From 77060314756913ee0bf50e6d56ba87f97eee4c85 Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 21 Jul 2020 21:13:09 +0530 Subject: [PATCH 17/18] Fix TypeError on PHP 8 --- src/Utility/Text.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Utility/Text.php b/src/Utility/Text.php index c7a9376afda..c4af3475c11 100644 --- a/src/Utility/Text.php +++ b/src/Utility/Text.php @@ -226,13 +226,13 @@ public static function insert(string $str, array $data, array $options = []): st $dataKeys = array_keys($data); $hashKeys = array_map('crc32', $dataKeys); - /** @var array $tempData */ + /** @var array $tempData */ $tempData = array_combine($dataKeys, $hashKeys); krsort($tempData); foreach ($tempData as $key => $hashVal) { $key = sprintf($format, preg_quote($key, '/')); - $str = preg_replace($key, $hashVal, $str); + $str = preg_replace($key, (string)$hashVal, $str); } /** @var array $dataReplacements */ $dataReplacements = array_combine($hashKeys, array_values($data)); From 672760ca9d016b722709d6d234a10e0e2c7ffb42 Mon Sep 17 00:00:00 2001 From: mcsknp Date: Wed, 22 Jul 2020 09:26:26 +0900 Subject: [PATCH 18/18] use assertSame in test case cakephp#14810 --- tests/TestCase/ORM/EntityTest.php | 6 +++--- tests/TestCase/ORM/MarshallerTest.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/TestCase/ORM/EntityTest.php b/tests/TestCase/ORM/EntityTest.php index 129730e7ee7..c90a94e0438 100644 --- a/tests/TestCase/ORM/EntityTest.php +++ b/tests/TestCase/ORM/EntityTest.php @@ -71,11 +71,11 @@ public function testSetMultiplePropertiesNoSetters() $this->assertEquals(1, $entity->getOriginal('id')); $entity->set(['foo', 'bar']); - $this->assertEquals('foo', $entity->get('0')); - $this->assertEquals('bar', $entity->get('1')); + $this->assertSame('foo', $entity->get('0')); + $this->assertSame('bar', $entity->get('1')); $entity->set(['sample']); - $this->assertEquals('sample', $entity->get('0')); + $this->assertSame('sample', $entity->get('0')); } /** diff --git a/tests/TestCase/ORM/MarshallerTest.php b/tests/TestCase/ORM/MarshallerTest.php index d5e4b53c881..e0ef9441804 100644 --- a/tests/TestCase/ORM/MarshallerTest.php +++ b/tests/TestCase/ORM/MarshallerTest.php @@ -147,8 +147,8 @@ public function testOneWithNumericField() ]; $marshall = new Marshaller($this->articles); $result = $marshall->one($data, []); - $this->assertEquals($data[0], $result->get('0')); - $this->assertEquals($data[1], $result->get('1')); + $this->assertSame($data[0], $result->get('0')); + $this->assertSame($data[1], $result->get('1')); } /**