|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * Cypher DSL |
| 5 | + * Copyright (C) 2021 Wikibase Solutions |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or |
| 8 | + * modify it under the terms of the GNU General Public License |
| 9 | + * as published by the Free Software Foundation; either version 2 |
| 10 | + * of the License, or (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program; if not, write to the Free Software |
| 19 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | + */ |
| 21 | + |
| 22 | +namespace WikibaseSolutions\CypherDSL\Tests\Unit\Traits; |
| 23 | + |
| 24 | +use PHPUnit\Framework\MockObject\MockObject; |
| 25 | +use PHPUnit\Framework\TestCase; |
| 26 | +use WikibaseSolutions\CypherDSL\GreaterThan; |
| 27 | +use WikibaseSolutions\CypherDSL\GreaterThanOrEqual; |
| 28 | +use WikibaseSolutions\CypherDSL\LessThan; |
| 29 | +use WikibaseSolutions\CypherDSL\LessThanOrEqual; |
| 30 | +use WikibaseSolutions\CypherDSL\Tests\Unit\TestHelper; |
| 31 | +use WikibaseSolutions\CypherDSL\Traits\ComparableTypeTrait; |
| 32 | +use WikibaseSolutions\CypherDSL\Types\PropertyTypes\ComparableType; |
| 33 | + |
| 34 | +/** |
| 35 | + * @covers \WikibaseSolutions\CypherDSL\Traits\NumeralTypeTrait |
| 36 | + */ |
| 37 | +class ComparableTypeTraitTest extends TestCase |
| 38 | +{ |
| 39 | + use TestHelper; |
| 40 | + |
| 41 | + /** |
| 42 | + * @var MockObject|ComparableType |
| 43 | + */ |
| 44 | + private $a; |
| 45 | + |
| 46 | + /** |
| 47 | + * @var MockObject|ComparableType |
| 48 | + */ |
| 49 | + private $b; |
| 50 | + |
| 51 | + public function setUp(): void |
| 52 | + { |
| 53 | + $this->a = new class () implements ComparableType { |
| 54 | + use ComparableTypeTrait; |
| 55 | + |
| 56 | + public function toQuery(): string |
| 57 | + { |
| 58 | + return '10'; |
| 59 | + } |
| 60 | + }; |
| 61 | + $this->b = $this->getQueryConvertableMock(ComparableType::class, "date({year: 2020, month: 12, day: 5})"); |
| 62 | + } |
| 63 | + |
| 64 | + public function testGt(): void |
| 65 | + { |
| 66 | + $gt = $this->a->gt($this->b); |
| 67 | + |
| 68 | + $this->assertInstanceOf(GreaterThan::class, $gt); |
| 69 | + |
| 70 | + $this->assertTrue($gt->insertsParentheses()); |
| 71 | + $this->assertEquals($this->a, $gt->getLeft()); |
| 72 | + $this->assertEquals($this->b, $gt->getRight()); |
| 73 | + } |
| 74 | + |
| 75 | + public function testGtNoParentheses(): void |
| 76 | + { |
| 77 | + $gt = $this->a->gt($this->b, false); |
| 78 | + |
| 79 | + $this->assertInstanceOf(GreaterThan::class, $gt); |
| 80 | + |
| 81 | + $this->assertFalse($gt->insertsParentheses()); |
| 82 | + $this->assertEquals($this->a, $gt->getLeft()); |
| 83 | + $this->assertEquals($this->b, $gt->getRight()); |
| 84 | + } |
| 85 | + |
| 86 | + public function testGte(): void |
| 87 | + { |
| 88 | + $gte = $this->a->gte($this->b); |
| 89 | + |
| 90 | + $this->assertInstanceOf(GreaterThanOrEqual::class, $gte); |
| 91 | + |
| 92 | + $this->assertTrue($gte->insertsParentheses()); |
| 93 | + $this->assertEquals($this->a, $gte->getLeft()); |
| 94 | + $this->assertEquals($this->b, $gte->getRight()); |
| 95 | + } |
| 96 | + |
| 97 | + public function testGteNoParentheses(): void |
| 98 | + { |
| 99 | + $gte = $this->a->gte($this->b, false); |
| 100 | + |
| 101 | + $this->assertInstanceOf(GreaterThanOrEqual::class, $gte); |
| 102 | + |
| 103 | + $this->assertFalse($gte->insertsParentheses()); |
| 104 | + $this->assertEquals($this->a, $gte->getLeft()); |
| 105 | + $this->assertEquals($this->b, $gte->getRight()); |
| 106 | + } |
| 107 | + |
| 108 | + public function testLt(): void |
| 109 | + { |
| 110 | + $lt = $this->a->lt($this->b); |
| 111 | + |
| 112 | + $this->assertInstanceOf(LessThan::class, $lt); |
| 113 | + |
| 114 | + $this->assertTrue($lt->insertsParentheses()); |
| 115 | + $this->assertEquals($this->a, $lt->getLeft()); |
| 116 | + $this->assertEquals($this->b, $lt->getRight()); |
| 117 | + } |
| 118 | + |
| 119 | + public function testLtNoParentheses(): void |
| 120 | + { |
| 121 | + $lt = $this->a->lt($this->b, false); |
| 122 | + |
| 123 | + $this->assertInstanceOf(LessThan::class, $lt); |
| 124 | + |
| 125 | + $this->assertFalse($lt->insertsParentheses()); |
| 126 | + $this->assertEquals($this->a, $lt->getLeft()); |
| 127 | + $this->assertEquals($this->b, $lt->getRight()); |
| 128 | + } |
| 129 | + |
| 130 | + public function testLte(): void |
| 131 | + { |
| 132 | + $lte = $this->a->lte($this->b); |
| 133 | + |
| 134 | + $this->assertInstanceOf(LessThanOrEqual::class, $lte); |
| 135 | + |
| 136 | + $this->assertTrue($lte->insertsParentheses()); |
| 137 | + $this->assertEquals($this->a, $lte->getLeft()); |
| 138 | + $this->assertEquals($this->b, $lte->getRight()); |
| 139 | + } |
| 140 | + |
| 141 | + public function testLteNoParentheses(): void |
| 142 | + { |
| 143 | + $lte = $this->a->lte($this->b, false); |
| 144 | + |
| 145 | + $this->assertInstanceOf(LessThanOrEqual::class, $lte); |
| 146 | + |
| 147 | + $this->assertFalse($lte->insertsParentheses()); |
| 148 | + $this->assertEquals($this->a, $lte->getLeft()); |
| 149 | + $this->assertEquals($this->b, $lte->getRight()); |
| 150 | + } |
| 151 | +} |
0 commit comments