CrossSchemaTableExpressionTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.3.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Database\Expression;
  16. use Cake\Database\Expression\CrossSchemaTableExpression;
  17. use Cake\Database\Expression\IdentifierExpression;
  18. use Cake\Database\ValueBinder;
  19. use Cake\TestSuite\TestCase;
  20. /**
  21. * Tests CrossSchemaTableExpression class
  22. */
  23. class CrossSchemaTableExpressionTest extends TestCase
  24. {
  25. /**
  26. * Test sql method with ExpressionInterfaces passed and without
  27. */
  28. public function testSql()
  29. {
  30. $expression = new CrossSchemaTableExpression(
  31. new IdentifierExpression('schema'),
  32. new IdentifierExpression('table')
  33. );
  34. $this->assertEquals('schema.table', $expression->sql(new ValueBinder()));
  35. $expression = new CrossSchemaTableExpression('schema', 'table');
  36. $this->assertEquals('schema.table', $expression->sql(new ValueBinder()));
  37. }
  38. /**
  39. * Test traverse method with ExpressionInterfaces passed and without
  40. */
  41. public function testTraverse()
  42. {
  43. $expressions = [];
  44. $collector = function ($e) use (&$expressions) {
  45. $expressions[] = $e;
  46. };
  47. $expression = new CrossSchemaTableExpression(
  48. new IdentifierExpression('schema'),
  49. new IdentifierExpression('table')
  50. );
  51. $expression->traverse($collector);
  52. $this->assertEquals([
  53. new IdentifierExpression('schema'),
  54. new IdentifierExpression('table')
  55. ], $expressions);
  56. $expressions = [];
  57. $expression = new CrossSchemaTableExpression('schema', 'table');
  58. $expression->traverse($collector);
  59. $this->assertEquals([], $expressions);
  60. }
  61. }