Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

PHPORM-45 Add Query\Builder::toMql() to simplify comprehensive query tests #6

Merged
merged 5 commits into from
Jul 12, 2023

Conversation

GromNaN
Copy link
Owner

@GromNaN GromNaN commented Jul 11, 2023

Fix PHPORM-45

Extracted from #4

@GromNaN GromNaN requested review from alcaeus and jmikola July 11, 2023 17:45
{
/**
* Builder::aggregate() and Builder::count() cannot be tested because they return the result,
* without modifying the builder.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

];

yield [
['aggregate' => [[['$group' => ['_id' => ['foo' => '$foo'], 'foo' => ['$last' => '$foo']]]], []]],
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This translation of the "group" operation will be investigated. #4 (comment)
https://jira.mongodb.org/browse/PHPORM-48

use MongoDB\BSON\UTCDateTime;
use PHPUnit\Framework\TestCase;

class BuilderTest extends TestCase
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new test class will be reserved to unit-tests on generated queries.
The QueryBuilderTest class have a tearDown method that slow down the tests and make it depend on a server.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In PHPLIB we have a few of those instances, and we usually name the database-dependent test SomethingFunctionalTest to indicate the difference to FunctionalTest. We may want to apply the same pattern here to avoid confusion between QueryBuilderTest and BuilderTest.

];

return new Collection($results);
return ['count' => [$wheres, []]];
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to #4 (comment)
I came back to "count" for now. Otherwise there is a test failure.


1) Jenssegers\Mongodb\Tests\TransactionTest::testQuery
Failed asserting that 0 matches expected 1.

tests/TransactionTest.php:302

Comment on lines 229 to 232
if ($this->columns === null) {
$this->columns = $columns;
if ($this->columns !== null) {
$columns = $this->columns;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure about this change as it may have side effects. Looking at the usages of $this->columns, it is used in various other methods of this class and in the Laravel framework itself. What was the reason for not storing the columns? Was it to be able to run toMql repeatedly without modifying the underlying object?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the $columns argument from toMql to stick to the current behavior. My goal is that toMql method does not alter the query.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense 👍

@GromNaN GromNaN merged commit 60a22f4 into master Jul 12, 2023
@GromNaN GromNaN deleted the PHPORM-45 branch July 12, 2023 11:56
GromNaN added a commit that referenced this pull request Aug 22, 2023
…tests (#6)

* PHPORM-45 Add Query\Builder::toMql() to simplify comprehensive query tests
* Move Query/Builder unit tests to a dedicated test class
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants