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 \Literals ;
23
+
24
+ use PHPUnit \Framework \TestCase ;
25
+ use TypeError ;
26
+ use WikibaseSolutions \CypherDSL \Literals \Boolean ;
27
+ use WikibaseSolutions \CypherDSL \Literals \Decimal ;
28
+ use WikibaseSolutions \CypherDSL \Literals \Literal ;
29
+ use WikibaseSolutions \CypherDSL \Literals \StringLiteral ;
30
+
31
+ /**
32
+ * @covers \WikibaseSolutions\CypherDSL\Decimal
33
+ */
34
+ class LiteralTest extends TestCase
35
+ {
36
+ public function testInt (): void
37
+ {
38
+ $ literal = Literal::fromLiteral (1 );
39
+ self ::assertInstanceOf (Decimal::class, $ literal );
40
+ self ::assertEquals ('1 ' , $ literal ->toQuery ());
41
+ }
42
+
43
+ public function testFloat (): void
44
+ {
45
+ $ literal = Literal::fromLiteral (1.2 );
46
+ self ::assertInstanceOf (Decimal::class, $ literal );
47
+ self ::assertEquals ('1.2 ' , $ literal ->toQuery ());
48
+ }
49
+
50
+ public function testString (): void
51
+ {
52
+ $ literal = Literal::fromLiteral ('abc ' );
53
+ self ::assertInstanceOf (StringLiteral::class, $ literal );
54
+ self ::assertEquals ("'abc' " , $ literal ->toQuery ());
55
+ }
56
+
57
+ public function testStringAble (): void
58
+ {
59
+ $ literal = Literal::fromLiteral (new class () {
60
+ public function __toString (): string
61
+ {
62
+ return 'stringable abc ' ;
63
+ }
64
+ });
65
+ self ::assertInstanceOf (StringLiteral::class, $ literal );
66
+ self ::assertEquals ("'stringable abc' " , $ literal ->toQuery ());
67
+ }
68
+
69
+ public function testBool (): void
70
+ {
71
+ $ literal = Literal::fromLiteral (true );
72
+ self ::assertInstanceOf (Boolean::class, $ literal );
73
+ self ::assertEquals ("true " , $ literal ->toQuery ());
74
+ }
75
+
76
+ public function testTypeError (): void
77
+ {
78
+ $ literal = Literal::fromLiteral (true );
79
+ $ this ->expectException (TypeError::class);
80
+ Literal::fromLiteral ($ literal );
81
+ }
82
+ }
0 commit comments