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 ;
23+
24+ use PHPUnit \Framework \TestCase ;
25+ use TypeError ;
26+ use WikibaseSolutions \CypherDSL \Contains ;
27+ use WikibaseSolutions \CypherDSL \Regex ;
28+ use WikibaseSolutions \CypherDSL \Types \AnyType ;
29+ use WikibaseSolutions \CypherDSL \Types \PropertyTypes \StringType ;
30+
31+ /**
32+ * @covers \WikibaseSolutions\CypherDSL\Regex
33+ */
34+ class RegexTest extends TestCase
35+ {
36+ use TestHelper;
37+
38+ public function testToQuery ()
39+ {
40+ $ regex = new Regex ($ this ->getQueryConvertableMock (StringType::class, "a " ), $ this ->getQueryConvertableMock (StringType::class, "b " ));
41+
42+ $ this ->assertSame ("(a =~ b) " , $ regex ->toQuery ());
43+ }
44+
45+ public function testCannotBeNested ()
46+ {
47+ $ regex = new Regex ($ this ->getQueryConvertableMock (StringType::class, "a " ), $ this ->getQueryConvertableMock (StringType::class, "b " ));
48+
49+ $ this ->expectException (TypeError::class);
50+
51+ $ regex = new Regex ($ regex , $ regex );
52+
53+ $ regex ->toQuery ();
54+ }
55+
56+ public function testDoesNotAcceptAnyTypeAsOperands ()
57+ {
58+ $ this ->expectException (TypeError::class);
59+
60+ $ regex = new Regex ($ this ->getQueryConvertableMock (AnyType::class, "a " ), $ this ->getQueryConvertableMock (AnyType::class, "b " ));
61+
62+ $ regex ->toQuery ();
63+ }
64+ }
0 commit comments