Skip to content

Commit 4274430

Browse files
authored
Merge pull request #11 from phalcon/fix-countable
Add test cases
2 parents c081436 + 24dab62 commit 4274430

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

.github/workflows/main.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,27 @@ name: Tests & Validations
22
on: [ push ]
33

44
jobs:
5-
phpcs:
5+
validations:
66
runs-on: ubuntu-latest
77
steps:
88
- uses: actions/checkout@v3
9-
- name: Run PHP_CodeSniffer
10-
run: docker run --rm -v $(pwd):/data cytopia/phpcs --standard=./phpcs.xml.dist
9+
10+
- name: Setup PHP
11+
uses: shivammathur/setup-php@v2
12+
with:
13+
php-version: '7.4'
14+
extensions: mbstring, intl, json, mongodb-1.16.0, phalcon, xdebug
15+
tools: pecl
16+
ini-values: apc.enable_cli=on, session.save_path=/tmp
17+
18+
- run: composer install --no-interaction --no-ansi --no-progress
19+
20+
- name: run psalm
21+
if: always()
22+
run: vendor/bin/psalm
23+
24+
- name: run phpcs
25+
run: vendor/bin/phpcs
1126

1227
run-tests:
1328
name: PHP ${{ matrix.php-versions }} with Phalcon ${{ matrix.phalcon-versions }}
@@ -27,6 +42,7 @@ jobs:
2742
phalcon-versions: [ '5.0.0', '5.0.1', '5.0.2', '5.0.3', '5.0.4', '5.0.5', '5.1.0', '5.1.1', '5.1.2', '5.1.3', '5.1.4', '5.2.0', '5.2.1', '5.2.2' ]
2843
steps:
2944
- uses: actions/checkout@v3
45+
3046
- name: Setup cache environment
3147
id: cache-env
3248
uses: shivammathur/cache-extensions@v1

Dockerfile

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/Mvc/Collection.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ public function getCollectionManager(): ManagerInterface
879879
* @return \MongoDB\Collection
880880
* @throws Exception
881881
*/
882-
protected function prepareCU()
882+
protected function prepareCU(): \MongoDB\Collection
883883
{
884884
if ($this->container === null) {
885885
throw new Exception('The services related to the ODM');
@@ -1015,7 +1015,7 @@ public function serialize(): string
10151015
* @param string $connectionService
10161016
* @return $this
10171017
*/
1018-
public function setConnectionService($connectionService): self
1018+
public function setConnectionService(string $connectionService): self
10191019
{
10201020
$this->collectionsManager->setConnectionService($this, $connectionService);
10211021

@@ -1182,7 +1182,7 @@ public static function getTypeMap($base = null): array
11821182
];
11831183

11841184
/** @noinspection NotOptimalIfConditionsInspection */
1185-
if (class_exists($base) && is_array($base::$typeMap)) {
1185+
if (class_exists($base)) {
11861186
$typeMap = array_merge($typeMap, $base::$typeMap);
11871187
}
11881188

@@ -1244,7 +1244,6 @@ public function unserialize($data): void
12441244
* Gets the default collectionsManager service
12451245
*/
12461246
$manager = $container->getShared("collectionManager");
1247-
12481247
if ($manager === null) {
12491248
throw new Exception(
12501249
"The injected service 'collectionManager' is not valid"

tests/integration/Collection/AggregateCest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Phalcon\Incubator\MongoDB\Mvc\Collection\Exception;
2020
use Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections\Robots;
2121
use Phalcon\Incubator\MongoDB\Test\Fixtures\Traits\DiTrait;
22+
use Traversable;
2223

2324
class AggregateCest
2425
{
@@ -69,12 +70,13 @@ public function mvcCollectionAggregate(IntegrationTester $I)
6970
$robots1 = Robots::aggregate([
7071
[
7172
'$match' => [
72-
'first_name' => 'Wall'
73+
'first_name' => 'Wall',
7374
]
7475
]
7576
]);
7677

7778
$I->assertInstanceOf(Cursor::class, $robots1);
79+
$I->assertInstanceOf(Traversable::class, $robots1);
7880

7981
foreach ($robots1 as $rb) {
8082
$I->assertIsArray($rb);

tests/integration/Collection/FindCest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Phalcon\Incubator\MongoDB\Mvc\Collection\Exception;
1919
use Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections\Robots;
2020
use Phalcon\Incubator\MongoDB\Test\Fixtures\Traits\DiTrait;
21+
use Traversable;
2122

2223
class FindCest
2324
{
@@ -77,7 +78,9 @@ public function mvcCollectionFind(IntegrationTester $I)
7778
}
7879

7980
$I->assertNotEmpty($robots);
81+
$I->assertInstanceOf(Traversable::class, $robots);
8082
$I->assertInstanceOf(Robots::class, $result[0]);
83+
$I->assertInstanceOf(Traversable::class, $robotsE);
8184
$I->assertCount(3, $result);
8285
$I->assertCount(2, $robotsE->toArray());
8386
}

0 commit comments

Comments
 (0)