Skip to content

Commit 1c7de64

Browse files
Write additional unit tests
1 parent 5192b95 commit 1c7de64

35 files changed

+411
-318
lines changed

src/Expressions/Parameter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ final class Parameter implements
7272
use ErrorTrait;
7373
use EscapeTrait;
7474
use NameGenerationTrait;
75+
7576
private string $parameter;
7677

7778
/**

src/Syntax/PropertyReplacement.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ public function mutates(): bool
7777
return $this->mutate;
7878
}
7979

80+
/**
81+
* Returns the name of the property to which we assign a (new) value.
82+
*
83+
* @return Property|Variable
84+
*/
85+
public function getProperty()
86+
{
87+
return $this->property;
88+
}
89+
90+
/**
91+
* Returns value to assign to the property.
92+
*/
93+
public function getValue(): AnyType
94+
{
95+
return $this->value;
96+
}
97+
8098
/**
8199
* @inheritDoc
82100
*/

tests/end-to-end/MoviesTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,50 @@ public function testMoviesAndActorsUpTo4HopsAwayFromKevinBacon(): void
135135

136136
$this->assertStringMatchesFormat('MATCH (:Person {name: \'Kevin Bacon\'})-[*1..4]-(%s) RETURN DISTINCT %s', $query->toQuery());
137137
}
138+
139+
public function testFindSomeoneToIntroduceTomHanksToTomCruise(): void
140+
{
141+
$tom = node('Person')->withProperties([
142+
'name' => 'Tom Hanks',
143+
]);
144+
145+
$cruise = node('Person')->withProperties([
146+
'name' => 'Tom Cruise',
147+
]);
148+
149+
$m = node();
150+
$m2 = node();
151+
$coActors = node();
152+
153+
$query = query()
154+
->match([
155+
$tom->relationshipTo($m, 'ACTED_IN')->relationshipFrom($coActors, 'ACTED_IN'),
156+
$coActors->relationshipTo($m2, 'ACTED_IN')->relationshipFrom($cruise, 'ACTED_IN'),
157+
])
158+
->returning([$tom, $m, $coActors, $m2, $cruise]);
159+
160+
$this->assertStringMatchesFormat('MATCH (%s:Person {name: \'Tom Hanks\'})-[:ACTED_IN]->(%s)<-[:ACTED_IN]-(%s), (%s)-[:ACTED_IN]->(%s)<-[:ACTED_IN]-(%s:Person {name: \'Tom Cruise\'}) RETURN %s, %s, %s, %s', $query->toQuery());
161+
}
162+
163+
public function testDeleteAllMovieAndPersonNodes(): void
164+
{
165+
$n = node();
166+
167+
$query = query()
168+
->match($n)
169+
->delete($n, true);
170+
171+
$this->assertStringMatchesFormat('MATCH (%s) DETACH DELETE %s', $query->toQuery());
172+
}
173+
174+
public function testProveThatMovieGraphIsGone(): void
175+
{
176+
$n = node();
177+
178+
$query = query()
179+
->match($n)
180+
->returning($n);
181+
182+
$this->assertStringMatchesFormat('MATCH (%s) RETURN %s', $query->toQuery());
183+
}
138184
}

tests/unit/Expressions/AliasTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* @covers \WikibaseSolutions\CypherDSL\Syntax\Alias
1818
*/
19-
class AliasTest extends TestCase
19+
final class AliasTest extends TestCase
2020
{
2121
private Alias $alias;
2222

tests/unit/Expressions/Literals/IntegerTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ public function testToQuery($number, string $expected): void
5959
$this->assertEquals($expected, $decimal->getValue());
6060
}
6161

62+
/**
63+
* @dataProvider provideInvalidInputData
64+
*/
65+
public function testInvalidInput($input): void
66+
{
67+
$this->expectException(TypeError::class);
68+
new Integer($input);
69+
}
70+
71+
6272
public function provideToQueryData(): array
6373
{
6474
return [
@@ -72,17 +82,7 @@ public function provideToQueryData(): array
7282
["-1238109438204130457284308235720483205", "-1238109438204130457284308235720483205"],
7383
];
7484
}
75-
76-
/**
77-
* @dataProvider wrongInputProvider
78-
*/
79-
public function testWrongInput($input): void
80-
{
81-
$this->expectException(TypeError::class);
82-
new Integer($input);
83-
}
84-
85-
public function wrongInputProvider(): array
85+
public function provideInvalidInputData(): array
8686
{
8787
return [
8888
['nonumber'],

tests/unit/Expressions/Operators/InTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@
1010
namespace WikibaseSolutions\CypherDSL\Tests\Unit\Expressions\Operators;
1111

1212
use PHPUnit\Framework\TestCase;
13-
use TypeError;
1413
use WikibaseSolutions\CypherDSL\Expressions\Literals\Boolean;
1514
use WikibaseSolutions\CypherDSL\Expressions\Literals\List_;
1615
use WikibaseSolutions\CypherDSL\Expressions\Operators\In;
1716
use WikibaseSolutions\CypherDSL\Expressions\Property;
1817
use WikibaseSolutions\CypherDSL\Expressions\Variable;
19-
use WikibaseSolutions\CypherDSL\Types\AnyType;
18+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\BooleanType;
2019

2120
/**
2221
* @covers \WikibaseSolutions\CypherDSL\Expressions\Operators\In
2322
*/
24-
class InTest extends TestCase
23+
final class InTest extends TestCase
2524
{
2625
public function testToQuery(): void
2726
{
@@ -45,12 +44,10 @@ public function testToQueryNoParentheses(): void
4544
$this->assertSame("(v.a IN b IN [true, false])", $in->toQuery());
4645
}
4746

48-
public function testDoesNotAcceptAnyTypeAsOperands(): void
47+
public function testInstanceOfBooleanType(): void
4948
{
50-
$this->expectException(TypeError::class);
49+
$in = new In(new Property(new Variable('a'), 'a'), new Variable('b'));
5150

52-
$inequality = new In($this->createMock(AnyType::class), $this->createMock(AnyType::class));
53-
54-
$inequality->toQuery();
51+
$this->assertInstanceOf(BooleanType::class, $in);
5552
}
5653
}

tests/unit/Expressions/Operators/InequalityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* @covers \WikibaseSolutions\CypherDSL\Expressions\Operators\Inequality
2020
*/
21-
class InequalityTest extends TestCase
21+
final class InequalityTest extends TestCase
2222
{
2323
public function testToQuery(): void
2424
{

tests/unit/Expressions/Operators/IsNotNullTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
use PHPUnit\Framework\TestCase;
1313
use WikibaseSolutions\CypherDSL\Expressions\Literals\Boolean;
1414
use WikibaseSolutions\CypherDSL\Expressions\Operators\IsNotNull;
15+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\BooleanType;
1516

1617
/**
1718
* @covers \WikibaseSolutions\CypherDSL\Expressions\Operators\IsNotNull
1819
*/
19-
class IsNotNullTest extends TestCase
20+
final class IsNotNullTest extends TestCase
2021
{
2122
public function testToQuery(): void
2223
{
@@ -32,4 +33,11 @@ public function testToQuery(): void
3233

3334
$this->assertTrue($isNotNull->insertsParentheses());
3435
}
36+
37+
public function testInstanceOfBooleanType(): void
38+
{
39+
$isNotNull = new IsNotNull(new Boolean(true));
40+
41+
$this->assertInstanceOf(BooleanType::class, $isNotNull);
42+
}
3543
}

tests/unit/Expressions/Operators/IsNullTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
use PHPUnit\Framework\TestCase;
1313
use WikibaseSolutions\CypherDSL\Expressions\Literals\Boolean;
1414
use WikibaseSolutions\CypherDSL\Expressions\Operators\IsNull;
15+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\BooleanType;
1516

1617
/**
1718
* @covers \WikibaseSolutions\CypherDSL\Expressions\Operators\IsNull
1819
*/
19-
class IsNullTest extends TestCase
20+
final class IsNullTest extends TestCase
2021
{
2122
public function testToQuery(): void
2223
{
@@ -32,4 +33,11 @@ public function testToQuery(): void
3233

3334
$this->assertTrue($isNull->insertsParentheses());
3435
}
36+
37+
public function testInstanceOfBooleanType(): void
38+
{
39+
$isNull = new IsNull(new Boolean(true));
40+
41+
$this->assertInstanceOf(BooleanType::class, $isNull);
42+
}
3543
}

tests/unit/Expressions/Operators/LessThanOrEqualTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
use PHPUnit\Framework\TestCase;
1313
use WikibaseSolutions\CypherDSL\Expressions\Literals\Integer;
1414
use WikibaseSolutions\CypherDSL\Expressions\Operators\LessThanOrEqual;
15+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\BooleanType;
1516

1617
/**
1718
* @covers \WikibaseSolutions\CypherDSL\Expressions\Operators\LessThanOrEqual
1819
*/
19-
class LessThanOrEqualTest extends TestCase
20+
final class LessThanOrEqualTest extends TestCase
2021
{
2122
public function testToQuery(): void
2223
{
@@ -35,4 +36,11 @@ public function testToQueryNoParentheses(): void
3536

3637
$this->assertSame("10 <= 15", $lessThanOrEqual->toQuery());
3738
}
39+
40+
public function testInstanceOfBooleanType(): void
41+
{
42+
$lessThanOrEqual = new LessThanOrEqual(new Integer(1), new Integer(2));
43+
44+
$this->assertInstanceOf(BooleanType::class, $lessThanOrEqual);
45+
}
3846
}

0 commit comments

Comments
 (0)