Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test cases #11

Merged
merged 4 commits into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@ name: Tests & Validations
on: [ push ]

jobs:
phpcs:
validations:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run PHP_CodeSniffer
run: docker run --rm -v $(pwd):/data cytopia/phpcs --standard=./phpcs.xml.dist

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: mbstring, intl, json, mongodb-1.16.0, phalcon, xdebug
tools: pecl
ini-values: apc.enable_cli=on, session.save_path=/tmp

- run: composer install --no-interaction --no-ansi --no-progress

- name: run psalm
if: always()
run: vendor/bin/psalm

- name: run phpcs
run: vendor/bin/phpcs

run-tests:
name: PHP ${{ matrix.php-versions }} with Phalcon ${{ matrix.phalcon-versions }}
Expand All @@ -27,6 +42,7 @@ jobs:
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' ]
steps:
- uses: actions/checkout@v3

- name: Setup cache environment
id: cache-env
uses: shivammathur/cache-extensions@v1
Expand Down
6 changes: 0 additions & 6 deletions Dockerfile

This file was deleted.

7 changes: 3 additions & 4 deletions src/Mvc/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ public function getCollectionManager(): ManagerInterface
* @return \MongoDB\Collection
* @throws Exception
*/
protected function prepareCU()
protected function prepareCU(): \MongoDB\Collection
{
if ($this->container === null) {
throw new Exception('The services related to the ODM');
Expand Down Expand Up @@ -1015,7 +1015,7 @@ public function serialize(): string
* @param string $connectionService
* @return $this
*/
public function setConnectionService($connectionService): self
public function setConnectionService(string $connectionService): self
{
$this->collectionsManager->setConnectionService($this, $connectionService);

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

/** @noinspection NotOptimalIfConditionsInspection */
if (class_exists($base) && is_array($base::$typeMap)) {
if (class_exists($base)) {
$typeMap = array_merge($typeMap, $base::$typeMap);
}

Expand Down Expand Up @@ -1244,7 +1244,6 @@ public function unserialize($data): void
* Gets the default collectionsManager service
*/
$manager = $container->getShared("collectionManager");

if ($manager === null) {
throw new Exception(
"The injected service 'collectionManager' is not valid"
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/Collection/AggregateCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Phalcon\Incubator\MongoDB\Mvc\Collection\Exception;
use Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections\Robots;
use Phalcon\Incubator\MongoDB\Test\Fixtures\Traits\DiTrait;
use Traversable;

class AggregateCest
{
Expand Down Expand Up @@ -69,12 +70,13 @@ public function mvcCollectionAggregate(IntegrationTester $I)
$robots1 = Robots::aggregate([
[
'$match' => [
'first_name' => 'Wall'
'first_name' => 'Wall',
]
]
]);

$I->assertInstanceOf(Cursor::class, $robots1);
$I->assertInstanceOf(Traversable::class, $robots1);

foreach ($robots1 as $rb) {
$I->assertIsArray($rb);
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/Collection/FindCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Phalcon\Incubator\MongoDB\Mvc\Collection\Exception;
use Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections\Robots;
use Phalcon\Incubator\MongoDB\Test\Fixtures\Traits\DiTrait;
use Traversable;

class FindCest
{
Expand Down Expand Up @@ -77,7 +78,9 @@ public function mvcCollectionFind(IntegrationTester $I)
}

$I->assertNotEmpty($robots);
$I->assertInstanceOf(Traversable::class, $robots);
$I->assertInstanceOf(Robots::class, $result[0]);
$I->assertInstanceOf(Traversable::class, $robotsE);
$I->assertCount(3, $result);
$I->assertCount(2, $robotsE->toArray());
}
Expand Down
Loading