IdentifierExpressionTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 3.0.0
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Test\TestCase\Database\Expression;
  17. use Cake\Database\Expression\IdentifierExpression;
  18. use Cake\Database\ValueBinder;
  19. use Cake\TestSuite\TestCase;
  20. /**
  21. * Tests IdentifierExpression class
  22. */
  23. class IdentifierExpressionTest extends TestCase
  24. {
  25. /**
  26. * Tests getting and setting the field
  27. */
  28. public function testGetAndSet(): void
  29. {
  30. $expression = new IdentifierExpression('foo');
  31. $this->assertSame('foo', $expression->getIdentifier());
  32. $expression->setIdentifier('bar');
  33. $this->assertSame('bar', $expression->getIdentifier());
  34. }
  35. /**
  36. * Tests converting to sql
  37. */
  38. public function testSQL(): void
  39. {
  40. $expression = new IdentifierExpression('foo');
  41. $this->assertSame('foo', $expression->sql(new ValueBinder()));
  42. }
  43. /**
  44. * Tests setting collation.
  45. */
  46. public function testCollation(): void
  47. {
  48. $expresssion = new IdentifierExpression('test', 'utf8_general_ci');
  49. $this->assertSame('test COLLATE utf8_general_ci', $expresssion->sql(new ValueBinder()));
  50. }
  51. }