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

Cleanup and tests #2567

Merged
merged 19 commits into from Aug 22, 2023
Merged

Cleanup and tests #2567

merged 19 commits into from Aug 22, 2023

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Aug 21, 2023

This is the work of several weeks that was done on a parallel repository (GromNaN/laravel-mongodb) while the ownership of this library to @mongodb was discussed #2499 (comment).
The goal is to improve the maintainability of this library by adding tests, fixing bugs and keep in sync with Laravel changes.

Every commit is a Pull Request reviewed by @alcaeus and/or @jmikola.

Changelog:

  • Add classes to cast ObjectId and UUID instances #1
  • Add Query\Builder::toMql() to simplify comprehensive query tests #6
  • Fix Query\Builder::whereNot to use MongoDB $not operator #13
  • Fix Query\Builder::whereBetween to accept Carbon\Period object #10
  • Throw an exception for unsupported Query\Builder methods #9
  • Throw an exception when Query\Builder::orderBy() is used with invalid direction #7
  • Throw an exception when Query\Builder::push() is used incorrectly #5
  • Remove public property Query\Builder::$paginating #15
  • Remove call to deprecated Collection::count for countDocuments #18
  • Accept operators prefixed by $ in Query\Builder::orWhere #20
  • Remove Query\Builder::whereAll($column, $values). Use Query\Builder::where($column, 'all', $values) instead. #16
  • Fix validation of unique values when the validated value is found as part of an existing value. #21
  • Support % and _ in like expression #17

alcaeus and others added 19 commits June 29, 2023 10:33
* Skip MySQL tests if database is not available

* Introduce tests namespace
…tests (mongodb#6)

* PHPORM-45 Add Query\Builder::toMql() to simplify comprehensive query tests
* Move Query/Builder unit tests to a dedicated test class
…th invalid direction (mongodb#7)

* Convert only strings, let the driver fail for int values
* Add more tests on Builder::orderBy
…lications (mongodb#12)

* Add header documentation for classes & traits that can be used in applications
* Precise mixed types when possible
…eject invalid array (mongodb#10)

The Query\Builder::whereBetween() method can be used like this:

whereBetween('date_field', [min, max])
whereBetween('date_field', collect([min, max]))
whereBetween('date_field', CarbonPeriod)

Laravel allows other formats: the $values array is flatten and the builder assumes there are at least 2 elements and ignore the others. It's a design that can lead to misunderstandings. I prefer to raise an exception when we have incorrect values, rather than trying to guess what the developer would like to do.

Support for CarbonPeriod was fixed in Laravel 10: laravel/framework#46720 because the query builder was taking the 1st 2 values of the iterator instead of the start & end dates.
…$not` (mongodb#13)

`Query\Builder::whereNot` was simply ignoring the "not" and breaking the built query.
…$not` (mongodb#13) (mongodb#15)

`Query\Builder::whereNot` was simply ignoring the "not" and breaking the built query.
- Add tests on query builder methods that don't need to be fixed.
- Throw exception when calling unsupported methods: whereIntegerInRaw, orWhereIntegerInRaw, whereIntegerNotInRaw, orWhereIntegerNotInRaw
- Throw an exception when Query\Builder::where is called with only a column name
- Fix support for % and _ in like expression and escaped \% and \_
- Keep ilike and regexp operators as aliases for like and regex
- Allow /, # and ~ as regex delimiters
- Add functional tests on regexp and not regexp
- Add support for not regex
* PHPORM-35 Add various tests on Model _id

* Add assertion on expected value

* Test _id as array and object

* Remove tests for arrays and objects as identifiers when keyType is string

---------

Co-authored-by: Andreas Braun <git@alcaeus.org>
@codecov-commenter
Copy link

codecov-commenter commented Aug 22, 2023

Codecov Report

Patch coverage: 97.54% and project coverage change: +0.67% 🎉

Comparison is base (1303b5f) 89.91% compared to head (9f1f8f3) 90.59%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2567      +/-   ##
============================================
+ Coverage     89.91%   90.59%   +0.67%     
- Complexity      712      749      +37     
============================================
  Files            32       34       +2     
  Lines          1726     1787      +61     
============================================
+ Hits           1552     1619      +67     
+ Misses          174      168       -6     
Files Changed Coverage Δ
src/Collection.php 89.47% <ø> (ø)
src/Connection.php 89.02% <ø> (ø)
src/Eloquent/Casts/ObjectId.php 87.50% <87.50%> (ø)
src/Eloquent/Casts/BinaryUuid.php 88.23% <88.23%> (ø)
src/Query/Builder.php 93.98% <99.23%> (+2.35%) ⬆️
src/Auth/DatabaseTokenRepository.php 68.18% <100.00%> (ø)
src/Eloquent/EmbedsRelations.php 100.00% <100.00%> (ø)
src/Eloquent/HybridRelations.php 87.35% <100.00%> (-0.29%) ⬇️
src/Eloquent/Model.php 92.22% <100.00%> (+0.55%) ⬆️
src/Validation/DatabasePresenceVerifier.php 76.92% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alcaeus
Copy link
Member

alcaeus commented Aug 22, 2023

Ignoring StyleCI for the time being - we'll revisit CI tooling in the near future.

@alcaeus alcaeus merged commit 49ec43c into mongodb:master Aug 22, 2023
11 of 12 checks passed
@GromNaN GromNaN deleted the rebased-master branch August 22, 2023 08:17
@GromNaN GromNaN mentioned this pull request Aug 23, 2023
@divine
Copy link
Contributor

divine commented Aug 24, 2023

Ignoring StyleCI for the time being - we'll revisit CI tooling in the near future.

Hello,

For a long time, we've tried to get away from Styleci as we didn't have permission to disable it. Php-cs-fixer does the same work, so basically Styleci can be dropped forever...

Thanks!

@GromNaN GromNaN added this to the 4.0.0 milestone Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants