QueryRegressionTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  14. */
  15. namespace Cake\Test\TestCase\ORM;
  16. use Cake\ORM\Query;
  17. use Cake\ORM\Table;
  18. use Cake\ORM\TableRegistry;
  19. use Cake\TestSuite\TestCase;
  20. /**
  21. * Contains regression test for the Query builder
  22. *
  23. */
  24. class QueryRegressionTest extends TestCase {
  25. /**
  26. * Fixture to be used
  27. *
  28. * @var array
  29. */
  30. public $fixtures = ['core.user', 'core.article', 'core.tag', 'core.articles_tag'];
  31. /**
  32. * Tear down
  33. *
  34. * @return void
  35. */
  36. public function tearDown() {
  37. TableRegistry::clear();
  38. }
  39. /**
  40. * Test for https://github.com/cakephp/cakephp/issues/3087
  41. *
  42. * @return void
  43. */
  44. public function testSelectTimestampColumn() {
  45. $table = TableRegistry::get('users');
  46. $user = $table->find()->where(['id' => 1])->first();
  47. $this->assertEquals(new \DateTime('2007-03-17 01:16:23'), $user->created);
  48. $this->assertEquals(new \DateTime('2007-03-17 01:18:31'), $user->updated);
  49. }
  50. /**
  51. * Tests that EagerLoader does not try to create queries for associations having no
  52. * keys to compare against
  53. *
  54. * @return void
  55. */
  56. public function testEagerLoadingFromEmptyResults() {
  57. $table = TableRegistry::get('Articles');
  58. $table->belongsToMany('ArticlesTags');
  59. $results = $table->find()->where(['id >' => 100])->contain('ArticlesTags')->toArray();
  60. $this->assertEmpty($results);
  61. }
  62. }