Skip to content

Commit

Permalink
Merge branch 'master' into 3.next
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 28, 2018
2 parents ee8c5b5 + cbc4480 commit 3f46964
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/Cache/Engine/FileEngine.php
Expand Up @@ -337,6 +337,8 @@ protected function _clearDirectory($path, $now, $threshold)
//@codingStandardsIgnoreEnd
}
}

$dir->close();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/I18n/Parser/MoFileParser.php
Expand Up @@ -134,9 +134,9 @@ public function parse($resource)
continue;
}

$messages[$singularId] = $singular;
$messages[$singularId]['_context'][''] = $singular;
if ($pluralId !== null) {
$messages[$pluralId] = $plurals;
$messages[$pluralId]['_context'][''] = $plurals;
}
}

Expand Down
47 changes: 44 additions & 3 deletions tests/TestCase/Collection/CollectionTest.php
Expand Up @@ -19,6 +19,8 @@
use Cake\Collection\Collection;
use Cake\Collection\CollectionInterface;
use Cake\Collection\CollectionTrait;
use Cake\ORM\Entity;
use Cake\ORM\ResultSet;
use Cake\TestSuite\TestCase;
use NoRewindIterator;

Expand Down Expand Up @@ -696,10 +698,29 @@ public function testMaxCallback($items)
public function testMaxCallable($items)
{
$collection = new Collection($items);
$callback = function ($e) {
$this->assertEquals(['a' => ['b' => ['c' => 4]]], $collection->max(function ($e) {
return $e['a']['b']['c'] * - 1;
};
$this->assertEquals(['a' => ['b' => ['c' => 4]]], $collection->max($callback));
}));
}

/**
* Test max with a collection of Entities
*
* @return void
*/
public function testMaxWithEntities()
{
$collection = new Collection([
new Entity(['id' => 1, 'count' => 18]),
new Entity(['id' => 2, 'count' => 9]),
new Entity(['id' => 3, 'count' => 42]),
new Entity(['id' => 4, 'count' => 4]),
new Entity(['id' => 5, 'count' => 22])
]);

$expected = new Entity(['id' => 3, 'count' => 42]);

$this->assertEquals($expected, $collection->max('count'));
}

/**
Expand All @@ -714,6 +735,26 @@ public function testMin($items)
$this->assertEquals(['a' => ['b' => ['c' => 4]]], $collection->min('a.b.c'));
}

/**
* Test min with a collection of Entities
*
* @return void
*/
public function testMinWithEntities()
{
$collection = new Collection([
new Entity(['id' => 1, 'count' => 18]),
new Entity(['id' => 2, 'count' => 9]),
new Entity(['id' => 3, 'count' => 42]),
new Entity(['id' => 4, 'count' => 4]),
new Entity(['id' => 5, 'count' => 22])
]);

$expected = new Entity(['id' => 4, 'count' => 4]);

$this->assertEquals($expected, $collection->min('count'));
}

/**
* Provider for some groupBy tests
*
Expand Down
80 changes: 64 additions & 16 deletions tests/TestCase/I18n/Parser/MoFileParserTest.php
Expand Up @@ -35,12 +35,24 @@ public function testParse()
$messages = $parser->parse($file);
$this->assertCount(3, $messages);
$expected = [
'%d = 1 (from core)' => '%d = 1 (from core translated)',
'%d = 1 (from core)' => [
'_context' => [
'' => '%d = 1 (from core translated)'
]
],
'%d = 0 or > 1 (from core)' => [
'%d = 1 (from core translated)',
'%d = 0 or > 1 (from core translated)'
'_context' => [
'' => [
'%d = 1 (from core translated)',
'%d = 0 or > 1 (from core translated)'
]
]
],
'Plural Rule 1 (from core)' => 'Plural Rule 1 (from core translated)'
'Plural Rule 1 (from core)' => [
'_context' => [
'' => 'Plural Rule 1 (from core translated)'
]
]
];
$this->assertEquals($expected, $messages);
}
Expand All @@ -57,10 +69,22 @@ public function testParse0()
$messages = $parser->parse($file);
$this->assertCount(3, $messages);
$expected = [
'Plural Rule 1 (from core)' => 'Plural Rule 0 (from core translated)',
'%d = 1 (from core)' => '%d ends with any # (from core translated)',
'Plural Rule 1 (from core)' => [
'_context' => [
'' => 'Plural Rule 0 (from core translated)'
]
],
'%d = 1 (from core)' => [
'_context' => [
'' => '%d ends with any # (from core translated)'
]
],
'%d = 0 or > 1 (from core)' => [
'%d ends with any # (from core translated)',
'_context' => [
'' => [
'%d ends with any # (from core translated)',
]
]
],
];
$this->assertEquals($expected, $messages);
Expand All @@ -78,13 +102,25 @@ public function testParse2()
$messages = $parser->parse($file);
$this->assertCount(3, $messages);
$expected = [
'%d = 1 (from core)' => '%d is 1 (from core translated)',
'%d = 1 (from core)' => [
'_context' => [
'' => '%d is 1 (from core translated)'
]
],
'%d = 0 or > 1 (from core)' => [
'%d is 1 (from core translated)',
'%d ends in 2-4, not 12-14 (from core translated)',
'%d everything else (from core translated)'
'_context' => [
'' => [
'%d is 1 (from core translated)',
'%d ends in 2-4, not 12-14 (from core translated)',
'%d everything else (from core translated)'
]
]
],
'Plural Rule 1 (from core)' => 'Plural Rule 9 (from core translated)'
'Plural Rule 1 (from core)' => [
'_context' => [
'' => 'Plural Rule 9 (from core translated)'
]
]
];
$this->assertEquals($expected, $messages);
}
Expand All @@ -101,7 +137,11 @@ public function testParseFull()
$messages = $parser->parse($file);
$this->assertCount(5, $messages);
$expected = [
'Plural Rule 1' => 'Plural Rule 1 (translated)',
'Plural Rule 1' => [
'_context' => [
'' => 'Plural Rule 1 (translated)'
]
],
'%d = 1' => [
'_context' => [
'This is the context' => 'First Context trasnlation',
Expand All @@ -116,10 +156,18 @@ public function testParseFull()
]
]
],
'%-5d = 1' => '%-5d = 1 (translated)',
'%-5d = 1' => [
'_context' => [
'' => '%-5d = 1 (translated)'
]
],
'%-5d = 0 or > 1' => [
'%-5d = 1 (translated)',
'%-5d = 0 or > 1 (translated)'
'_context' => [
'' => [
'%-5d = 1 (translated)',
'%-5d = 0 or > 1 (translated)'
]
]
]
];
$this->assertEquals($expected, $messages);
Expand Down
38 changes: 38 additions & 0 deletions tests/TestCase/ORM/ResultSetTest.php
Expand Up @@ -21,6 +21,7 @@
use Cake\ORM\ResultSet;
use Cake\ORM\Table;
use Cake\TestSuite\TestCase;
use TestApp\Model\Entity\Article;

/**
* ResultSet test case.
Expand Down Expand Up @@ -417,4 +418,41 @@ public function testIsEmptyDoesNotConsumeData()
$res->isEmpty();
$this->assertCount(6, $res->toArray());
}

/**
* Test that ResultSet
*
* @return void
*/
public function testCollectionMinAndMax()
{
$query = $this->table->find('all');

$min = $query->min('id');
$minExpected = $this->table->get(1);

$max = $query->max('id');
$maxExpected = $this->table->get(3);

$this->assertEquals($minExpected, $min);
$this->assertEquals($maxExpected, $max);
}

/**
* Test that ResultSet
*
* @return void
*/
public function testCollectionMinAndMaxWithAggregateField()
{
$query = $this->table->find();
$query->select([
'counter' => 'COUNT(*)'
])->group('author_id');

$min = $query->min('counter');
$max = $query->max('counter');

$this->assertTrue($max > $min);
}
}

0 comments on commit 3f46964

Please sign in to comment.