Skip to content

Commit 58109f5

Browse files
committed
added haspropertiestype test
1 parent a730caf commit 58109f5

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

src/Traits/HasPropertiesTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
trait HasPropertiesTrait
1010
{
11+
use ErrorTrait;
12+
1113
private ?PropertyMap $properties = null;
1214

1315
/**
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace WikibaseSolutions\CypherDSL\Tests\Unit\Traits;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use WikibaseSolutions\CypherDSL\PropertyMap;
7+
use WikibaseSolutions\CypherDSL\Query;
8+
use WikibaseSolutions\CypherDSL\Traits\HasPropertiesTrait;
9+
10+
class HasPropertiesTraitTest extends TestCase
11+
{
12+
private $propertyTrait;
13+
14+
public function setUp(): void
15+
{
16+
$this->propertyTrait = new class {
17+
use HasPropertiesTrait {
18+
initialiseProperties as public;
19+
}
20+
};
21+
}
22+
23+
public function testGetProperties(): void
24+
{
25+
self::assertNull($this->propertyTrait->getProperties());
26+
}
27+
28+
public function testWithPropertiesArray(): void
29+
{
30+
$this->propertyTrait->withProperties(['x' => Query::literal('y')]);
31+
32+
self::assertEquals(
33+
new PropertyMap(['x' => Query::literal('y')]),
34+
$this->propertyTrait->getProperties()
35+
);
36+
}
37+
38+
public function testWithPropertiesMap(): void
39+
{
40+
$this->propertyTrait->withProperties(new PropertyMap(['x' => Query::literal('y')]));
41+
42+
self::assertEquals(
43+
new PropertyMap(['x' => Query::literal('y')]),
44+
$this->propertyTrait->getProperties()
45+
);
46+
}
47+
48+
public function testWithProperty(): void
49+
{
50+
$this->propertyTrait->withProperty('x', Query::literal('y'));
51+
$this->propertyTrait->withProperty('z', Query::literal('z'));
52+
53+
self::assertEquals(
54+
new PropertyMap(['x' => Query::literal('y'), 'z' => Query::literal('z')]),
55+
$this->propertyTrait->getProperties()
56+
);
57+
}
58+
59+
public function testInitialise(): void
60+
{
61+
$this->propertyTrait->initialiseProperties();
62+
63+
self::assertEquals(new PropertyMap(), $this->propertyTrait->getProperties());
64+
}
65+
}

0 commit comments

Comments
 (0)