Skip to content

Commit 13c8de4

Browse files
author
Wout Gevaert
committed
Fix the currently broken tests.
We might need some more tests for the new functionalities, but we do have the old tests working now which is nice
1 parent e187b9a commit 13c8de4

26 files changed

+136
-203
lines changed

tests/Unit/Clauses/ReturnClauseTest.php

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
namespace WikibaseSolutions\CypherDSL\Tests\Unit\Clauses;
2323

2424
use PHPUnit\Framework\TestCase;
25+
use WikibaseSolutions\CypherDSL\Syntax\Alias;
26+
use WikibaseSolutions\CypherDSL\Patterns\Node;
27+
use WikibaseSolutions\CypherDSL\Patterns\Path;
28+
use WikibaseSolutions\CypherDSL\Expressions\Variable;
2529
use WikibaseSolutions\CypherDSL\Clauses\ReturnClause;
2630
use WikibaseSolutions\CypherDSL\Types\AnyType;
2731

@@ -44,6 +48,7 @@ public function testSingleColumn(): void
4448
{
4549
$return = new ReturnClause();
4650
$column = $this->createMock(AnyType::class);
51+
$column->method('toQuery')->willReturn('a');
4752
$return->addColumn($column);
4853

4954
$this->assertSame("RETURN a", $return->toQuery());
@@ -55,73 +60,73 @@ public function testMultipleColumns(): void
5560
{
5661
$return = new ReturnClause();
5762

58-
$columnA = $this->createMock(AnyType::class);
59-
$columnB = $this->createMock(AnyType::class);
60-
$columnC = $this->createMock(AnyType::class);
63+
$columnA = new Variable('a');
64+
$columnB = (new Path)->withVariable('b');
65+
$columnC = (new Node)->withVariable('c');
6166

6267
$return->addColumn($columnA);
6368
$return->addColumn($columnB);
6469
$return->addColumn($columnC);
6570

6671
$this->assertSame("RETURN a, b, c", $return->toQuery());
67-
$this->assertSame([$columnA, $columnB, $columnC], $return->getColumns());
72+
$this->assertSame([$columnA, $columnB->getVariable(), $columnC->getVariable()], $return->getColumns());
6873
$this->assertFalse($return->isDistinct());
6974
}
7075

7176
public function testSingleAlias(): void
7277
{
7378
$return = new ReturnClause();
74-
$column = $this->createMock(AnyType::class);
75-
$return->addColumn($column, "b");
79+
$column = new Alias(new Variable('a'), new Variable('b'));
80+
$return->addColumn($column);
7681

7782
$this->assertSame("RETURN a AS b", $return->toQuery());
78-
$this->assertSame(['b' => $column], $return->getColumns());
83+
$this->assertSame([$column], $return->getColumns());
7984
$this->assertFalse($return->isDistinct());
8085
}
8186

8287
public function testMultipleAliases(): void
8388
{
8489
$return = new ReturnClause();
85-
$columnA = $this->createMock(AnyType::class);
86-
$columnB = $this->createMock(AnyType::class);
87-
$return->addColumn($columnA, "b");
88-
$return->addColumn($columnB, "c");
90+
$aliasA = new Alias(new Variable('a'),new Variable('b'));
91+
$aliasB = new Alias(new Variable('b'),new Variable('c'));
92+
$return->addColumn($aliasA);
93+
$return->addColumn($aliasB);
8994

9095
$this->assertSame("RETURN a AS b, b AS c", $return->toQuery());
91-
$this->assertSame(['b' => $columnA, 'c' => $columnB], $return->getColumns());
96+
$this->assertSame([$aliasA, $aliasB], $return->getColumns());
9297
$this->assertFalse($return->isDistinct());
9398
}
9499

95100
public function testMixedAliases(): void
96101
{
97102
$return = new ReturnClause();
98-
$columnA = $this->createMock(AnyType::class);
99-
$columnB = $this->createMock(AnyType::class);
100-
$columnC = $this->createMock(AnyType::class);
101-
$return->addColumn($columnA, "b");
103+
$columnA = new Alias(new Variable('a'), new Variable('b'));
104+
$columnB = new Variable('c');
105+
$columnC = new Alias(new Variable('b'), new Variable('c'));
106+
$return->addColumn($columnA);
102107
$return->addColumn($columnB);
103-
$return->addColumn($columnC, "c");
108+
$return->addColumn($columnC);
104109

105110
$this->assertSame("RETURN a AS b, c, b AS c", $return->toQuery());
106-
$this->assertEquals(['b' => $columnA, $columnB, 'c' => $columnA], $return->getColumns());
111+
$this->assertEquals([$columnA, $columnB, $columnC], $return->getColumns());
107112
$this->assertFalse($return->isDistinct());
108113
}
109114

110115
public function testAliasIsEscaped(): void
111116
{
112117
$return = new ReturnClause();
113-
$column = $this->createMock(AnyType::class);
114-
$return->addColumn($column, ":");
118+
$column = new Alias(new Variable('a'), new Variable(':'));
119+
$return->addColumn($column);
115120

116121
$this->assertSame("RETURN a AS `:`", $return->toQuery());
117-
$this->assertSame([':' => $column], $return->getColumns());
122+
$this->assertSame([$column], $return->getColumns());
118123
$this->assertFalse($return->isDistinct());
119124
}
120125

121126
public function testReturnDistinct(): void
122127
{
123128
$return = new ReturnClause();
124-
$column = $this->createMock(AnyType::class);
129+
$column = new Variable('a');
125130
$return->addColumn($column);
126131
$return->setDistinct();
127132

tests/Unit/Clauses/WhereClauseTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ public function testExpression(): void
5252
$this->assertEquals($expression, $where->getExpression());
5353
}
5454

55-
/**
56-
* @doesNotPerformAssertions
57-
*/
5855
public function testDoesNotAcceptAnyType(): void
5956
{
6057
$where = new WhereClause();

tests/Unit/Clauses/WithClauseTest.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
use PHPUnit\Framework\TestCase;
2525
use WikibaseSolutions\CypherDSL\Clauses\WithClause;
26+
use WikibaseSolutions\CypherDSL\Expressions\Literals\String_;
27+
use WikibaseSolutions\CypherDSL\Expressions\Variable;
28+
use WikibaseSolutions\CypherDSL\Syntax\Alias;
2629
use WikibaseSolutions\CypherDSL\Types\AnyType;
2730

2831
/**
@@ -42,7 +45,7 @@ public function testEmptyClause(): void
4245
public function testSingleEntry(): void
4346
{
4447
$return = new WithClause();
45-
$entry = $this->createMock(AnyType::class);
48+
$entry = new Variable('a');
4649
$return->addEntry($entry);
4750

4851
$this->assertSame("WITH a", $return->toQuery());
@@ -52,9 +55,9 @@ public function testSingleEntry(): void
5255
public function testMultipleEntries(): void
5356
{
5457
$return = new WithClause();
55-
$entryA = $this->createMock(AnyType::class);
56-
$entryB = $this->createMock(AnyType::class);
57-
$entryC = $this->createMock(AnyType::class);
58+
$entryA = new Variable('a');
59+
$entryB = new Variable('b');
60+
$entryC = new Variable('c');
5861

5962
$return->addEntry($entryA);
6063
$return->addEntry($entryB);
@@ -67,49 +70,46 @@ public function testMultipleEntries(): void
6770
public function testSingleAlias(): void
6871
{
6972
$return = new WithClause();
70-
$entry = $this->createMock(AnyType::class);
71-
$return->addEntry($entry, "b");
73+
$entry = new Alias(new Variable('a'), new Variable('b'));
74+
$return->addEntry($entry);
7275

7376
$this->assertSame("WITH a AS b", $return->toQuery());
74-
$this->assertEquals(['b' => $entry], $return->getEntries());
77+
$this->assertEquals([$entry], $return->getEntries());
7578
}
7679

7780
public function testMultipleAliases(): void
7881
{
7982
$return = new WithClause();
80-
$entryA = $this->createMock(AnyType::class);
81-
$entryB = $this->createMock(AnyType::class);
83+
$entryA = new Alias(new Variable('a'), new Variable('b'));
84+
$entryB = new Alias(new Variable('b'), new Variable('c'));
8285

83-
$return->addEntry($entryA, "b");
84-
$return->addEntry($entryB, "c");
86+
$return->addEntry($entryA, $entryB);
8587

8688
$this->assertSame("WITH a AS b, b AS c", $return->toQuery());
87-
$this->assertEquals(['b' => $entryA, 'c' => $entryB], $return->getEntries());
89+
$this->assertEquals([$entryA, $entryB], $return->getEntries());
8890
}
8991

9092
public function testMixedAliases(): void
9193
{
9294
$return = new WithClause();
93-
$entryA = $this->createMock(AnyType::class);
94-
$entryB = $this->createMock(AnyType::class);
95-
$entryC = $this->createMock(AnyType::class);
95+
$entryA = new Alias(new Variable('a'), new Variable('b'));
96+
$entryB = new Variable('c');
97+
$entryC = new Alias(new Variable('b'), new Variable('c'));
9698

97-
$return->addEntry($entryA, "b");
98-
$return->addEntry($entryB);
99-
$return->addEntry($entryC, "c");
99+
$return->addEntry($entryA, $entryB, $entryC);
100100

101101
$this->assertSame("WITH a AS b, c, b AS c", $return->toQuery());
102-
$this->assertEquals(['b' => $entryA, $entryB, 'c' => $entryC], $return->getEntries());
102+
$this->assertEquals([$entryA, $entryB, $entryC], $return->getEntries());
103103
}
104104

105105
public function testAliasIsEscaped(): void
106106
{
107107
$return = new WithClause();
108-
$entry = $this->createMock(AnyType::class);
109-
$return->addEntry($entry, ":");
108+
$entry = new Alias(new Variable('__'), new Variable(':'));
109+
$return->addEntry($entry);
110110

111-
$this->assertSame("WITH a AS `:`", $return->toQuery());
112-
$this->assertEquals([':' => $entry], $return->getEntries());
111+
$this->assertSame("WITH `__` AS `:`", $return->toQuery());
112+
$this->assertEquals([$entry], $return->getEntries());
113113
}
114114

115115
/**

tests/Unit/Expressions/Operators/AdditionTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,26 @@ class AdditionTest extends TestCase
3535
{
3636
public function testToQuery(): void
3737
{
38-
$left = new Integer(10);
39-
$right = new Float_(15);
38+
$left = new Integer(10);
39+
$right = new Float_(15);
4040
$addition = new Addition($left, $right);
4141

42-
$this->assertSame("(10 + 15)", $addition->toQuery());
42+
$this->assertSame("(10 + 15.0)", $addition->toQuery());
4343

4444
$this->assertSame($left, $addition->getLeft());
4545
$this->assertSame($right, $addition->getRight());
4646

4747
$newAddition = new Addition($addition, $addition);
4848

49-
$this->assertSame("((10 + 15) + (10 + 15))", $newAddition->toQuery());
49+
$this->assertSame("((10 + 15.0) + (10 + 15.0))", $newAddition->toQuery());
5050

5151
$this->assertTrue($newAddition->insertsParentheses());
5252
$this->assertEquals($addition, $newAddition->getLeft());
5353
$this->assertEquals($addition, $newAddition->getRight());
5454

5555
$newAddition = new Addition($addition, $addition, false);
5656

57-
$this->assertSame("(10 + 15) + (10 + 15)", $newAddition->toQuery());
57+
$this->assertSame("(10 + 15.0) + (10 + 15.0)", $newAddition->toQuery());
5858

5959
$this->assertFalse($newAddition->insertsParentheses());
6060
$this->assertEquals($addition, $newAddition->getLeft());
@@ -63,8 +63,8 @@ public function testToQuery(): void
6363

6464
public function testDoesNotAcceptAnyTypeAsOperands(): void
6565
{
66-
$left = new Map([]);
67-
$right = new Map([]);
66+
$left = new Map([]);
67+
$right = new Map([]);
6868

6969
$this->expectException(TypeError::class);
7070

tests/Unit/Expressions/Operators/ContainsTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323

2424
use PHPUnit\Framework\TestCase;
2525
use TypeError;
26-
use WikibaseSolutions\CypherDSL\Expressions\Operators\Contains;
2726
use WikibaseSolutions\CypherDSL\Expressions\Literals\String_;
27+
use WikibaseSolutions\CypherDSL\Expressions\Operators\Contains;
28+
use WikibaseSolutions\CypherDSL\Expressions\Variable;
2829
use WikibaseSolutions\CypherDSL\Types\AnyType;
2930

3031
/**
@@ -35,21 +36,21 @@ class ContainsTest extends TestCase
3536

3637
public function testToQuery(): void
3738
{
38-
$contains = new Contains(new String_("a"), new String_("b"));
39+
$contains = new Contains(new Variable("a"), new String_("b"));
3940

40-
$this->assertSame("(a CONTAINS b)", $contains->toQuery());
41+
$this->assertSame("(a CONTAINS 'b')", $contains->toQuery());
4142
}
4243

4344
public function testToQueryNoParentheses(): void
4445
{
45-
$contains = new Contains(new String_("a"), new String_("b"), false);
46+
$contains = new Contains(new Variable("a"), new String_("b"), false);
4647

47-
$this->assertSame("a CONTAINS b", $contains->toQuery());
48+
$this->assertSame("a CONTAINS 'b'", $contains->toQuery());
4849
}
4950

5051
public function testCannotBeNested(): void
5152
{
52-
$contains = new Contains(new String_("a"), new String_("b"));
53+
$contains = new Contains(new Variable("a"), new String_("b"));
5354

5455
$this->expectException(TypeError::class);
5556

tests/Unit/Expressions/Operators/EndsWithTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use WikibaseSolutions\CypherDSL\Expressions\Operators\EndsWith;
2727
use WikibaseSolutions\CypherDSL\Types\AnyType;
2828
use WikibaseSolutions\CypherDSL\Expressions\Literals\String_;
29+
use WikibaseSolutions\CypherDSL\Expressions\Variable;
2930

3031
/**
3132
* @covers \WikibaseSolutions\CypherDSL\Expressions\Operators\EndsWith
@@ -35,21 +36,21 @@ class EndsWithTest extends TestCase
3536

3637
public function testToQuery(): void
3738
{
38-
$endsWith = new EndsWith(new String_("a"), new String_("b"));
39+
$endsWith = new EndsWith(new Variable("a"), new String_("b"));
3940

40-
$this->assertSame("(a ENDS WITH b)", $endsWith->toQuery());
41+
$this->assertSame("(a ENDS WITH 'b')", $endsWith->toQuery());
4142
}
4243

4344
public function testToQueryNoParentheses(): void
4445
{
45-
$endsWith = new EndsWith(new String_("a"), new String_("b"), false);
46+
$endsWith = new EndsWith(new Variable("a"), new String_("b"), false);
4647

47-
$this->assertSame("a ENDS WITH b", $endsWith->toQuery());
48+
$this->assertSame("a ENDS WITH 'b'", $endsWith->toQuery());
4849
}
4950

5051
public function testCannotBeNested(): void
5152
{
52-
$endsWith = new EndsWith(new String_("a"), new String_("b"));
53+
$endsWith = new EndsWith(new Variable("a"), new String_("b"));
5354

5455
$this->expectException(TypeError::class);
5556

tests/Unit/Expressions/Operators/EqualityTest.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use PHPUnit\Framework\TestCase;
2525
use TypeError;
2626
use WikibaseSolutions\CypherDSL\Expressions\Operators\Equality;
27-
use WikibaseSolutions\CypherDSL\Expressions\Property;
27+
use WikibaseSolutions\CypherDSL\Expressions\Literals\Integer;
2828
use WikibaseSolutions\CypherDSL\Expressions\Variable;
2929
use WikibaseSolutions\CypherDSL\Types\AnyType;
3030

@@ -33,10 +33,9 @@
3333
*/
3434
class EqualityTest extends TestCase
3535
{
36-
3736
public function testToQuery(): void
3837
{
39-
$equality = new Equality(new Property(new Variable('v'), "10"), new Property(new Variable('v'), "15"));
38+
$equality = new Equality(new Integer(10), new Integer(15));
4039

4140
$this->assertSame("(10 = 15)", $equality->toQuery());
4241

@@ -47,21 +46,12 @@ public function testToQuery(): void
4746

4847
public function testToQueryNoParentheses(): void
4948
{
50-
$equality = new Equality(new Property(new Variable('v'), "10"), new Property(new Variable('v'), "15"), false);
49+
$equality = new Equality(new Integer(10), new Integer(15), false);
5150

5251
$this->assertSame("10 = 15", $equality->toQuery());
5352

5453
$equality = new Equality($equality, $equality);
5554

5655
$this->assertSame("(10 = 15 = 10 = 15)", $equality->toQuery());
5756
}
58-
59-
public function testDoesNotAcceptAnyTypeAsOperands(): void
60-
{
61-
$this->expectException(TypeError::class);
62-
63-
$equality = new Equality($this->createMock(AnyType::class), $this->createMock(AnyType::class));
64-
65-
$equality->toQuery();
66-
}
6757
}

0 commit comments

Comments
 (0)