Skip to content

Commit

Permalink
Merge branch 'master' into 4.next
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jul 22, 2020
2 parents 542a1ab + b487171 commit 101d4ca
Show file tree
Hide file tree
Showing 89 changed files with 479 additions and 402 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ services:
- postgresql
- mysql

addons:
postgresql: '9.6'

cache:
directories:
- $HOME/.composer/cache
Expand Down
16 changes: 3 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,9 @@ 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); \
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 \
Expand Down Expand Up @@ -180,10 +173,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 $*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 2 additions & 12 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="3.11.2@d470903722cfcbc1cd04744c5491d3e6d13ec3d9">
<files psalm-version="3.12.2@7c7ebd068f8acaba211d4a2c707c4ba90874fa26">
<file src="src/Collection/CollectionTrait.php">
<ArgumentTypeCoercion occurrences="4">
<code>$iterator</code>
Expand Down Expand Up @@ -116,13 +116,8 @@
</ArgumentTypeCoercion>
</file>
<file src="src/ORM/Query.php">
<ArgumentTypeCoercion occurrences="6">
<ArgumentTypeCoercion occurrences="1">
<code>$this-&gt;_repository</code>
<code>$this-&gt;getRepository()</code>
<code>$this-&gt;getRepository()</code>
<code>$this-&gt;getRepository()</code>
<code>$this-&gt;getRepository()</code>
<code>$this-&gt;getRepository()</code>
</ArgumentTypeCoercion>
</file>
<file src="src/Routing/Middleware/RoutingMiddleware.php">
Expand Down Expand Up @@ -152,11 +147,6 @@
<code>new AssertionFailedError($message)</code>
</InternalClass>
</file>
<file src="src/TestSuite/Constraint/Session/SessionEquals.php">
<InternalClass occurrences="1">
<code>new AssertionFailedError('There is no stored session data. Perhaps you need to run a request?')</code>
</InternalClass>
</file>
<file src="src/TestSuite/Fixture/FixtureInjector.php">
<DeprecatedInterface occurrences="1">
<code>FixtureInjector</code>
Expand Down
1 change: 1 addition & 0 deletions src/Collection/CollectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Expression/TupleComparison.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Type/ExpressionTypeCasterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function _castToExpression($value, ?string $type = null)
$multi = $type !== $baseType;

if ($multi) {
/** @psalm-suppress InvalidArgument */
/** @psalm-var \Cake\Database\Type\ExpressionTypeInterface $converter */
return array_map([$converter, 'toExpression'], $value);
}

Expand Down
1 change: 1 addition & 0 deletions src/Datasource/EntityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 9 additions & 0 deletions src/Http/Middleware/CsrfProtectionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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']);
Expand Down
1 change: 1 addition & 0 deletions src/ORM/Behavior/Translate/EavStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ protected function rowMapper($results, $locale)

$row['_locale'] = $locale;
if ($hydrated) {
/** @psalm-suppress PossiblyInvalidMethodCall */
$row->clean();
}

Expand Down
1 change: 1 addition & 0 deletions src/ORM/Behavior/Translate/ShadowTableStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ protected function rowMapper($results, $locale)
unset($row['translation']);

if ($hydrated) {
/** @psalm-suppress PossiblyInvalidMethodCall */
$row->clean();
}

Expand Down
1 change: 1 addition & 0 deletions src/ORM/Marshaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/TestSuite/Constraint/Response/StatusCodeBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ protected function statusCodeBetween(int $min, int $max): bool
*/
protected function failureDescription($other): string
{
/** @psalm-suppress InternalMethod */
return $this->toString();
}
}
2 changes: 1 addition & 1 deletion src/TestSuite/IntegrationTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -692,6 +691,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;
Expand Down
4 changes: 2 additions & 2 deletions src/Utility/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> $tempData */
/** @var array<string, string|int> $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<string, mixed> $dataReplacements */
$dataReplacements = array_combine($hashKeys, array_values($data));
Expand Down
10 changes: 7 additions & 3 deletions src/Validation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()';

Expand Down Expand Up @@ -658,7 +662,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 = [
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Auth/ControllerAuthorizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Auth/FormAuthenticateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function testAuthenticatePasswordIsEmptyString(): void
]);

$this->auth = $this->getMockBuilder(FormAuthenticate::class)
->setMethods(['_checkFields'])
->onlyMethods(['_checkFields'])
->setConstructorArgs([
$this->collection,
['userModel' => 'Users'],
Expand Down
22 changes: 11 additions & 11 deletions tests/TestCase/Collection/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand All @@ -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())
Expand All @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Collection/Iterator/FilterIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Collection/Iterator/ReplaceIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Command/PluginAssetsCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit 101d4ca

Please sign in to comment.