Skip to content

Commit 47f054b

Browse files
authored
Merge pull request #17 from maltehuebner/add-comprehensive-tests
Add comprehensive test suite for all classes
2 parents 0b4489e + 7d72b69 commit 47f054b

55 files changed

Lines changed: 4402 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

composer.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,28 @@
1515
},
1616
"require-dev": {
1717
"phpunit/phpunit": "^9.5",
18-
"rector/rector": "^1.2"
18+
"rector/rector": "^1.2",
19+
"doctrine/orm": "^3.6",
20+
"doctrine/persistence": "^4.1"
1921
},
2022
"autoload": {
2123
"psr-4": {
2224
"MalteHuebner\\DataQueryBundle\\": "src/"
2325
}
2426
},
27+
"autoload-dev": {
28+
"psr-4": {
29+
"MalteHuebner\\DataQueryBundle\\Tests\\": "tests/"
30+
}
31+
},
2532
"authors": [
2633
{
2734
"name": "Malte Huebner",
2835
"email": "maltehuebner@gmx.org"
2936
}
3037
],
31-
"minimum-stability": "stable"
38+
"minimum-stability": "stable",
39+
"scripts": {
40+
"tests": "phpunit"
41+
}
3242
}

phpunit.xml.dist

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
failOnRisky="true"
7+
failOnWarning="true"
8+
>
9+
<testsuites>
10+
<testsuite name="DataQueryBundle Test Suite">
11+
<directory>tests</directory>
12+
</testsuite>
13+
</testsuites>
14+
15+
<coverage>
16+
<include>
17+
<directory suffix=".php">src</directory>
18+
</include>
19+
</coverage>
20+
</phpunit>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace MalteHuebner\DataQueryBundle\Tests\Attribute\EntityAttribute;
4+
5+
use MalteHuebner\DataQueryBundle\Attribute\EntityAttribute\DateTimeQueryable;
6+
use MalteHuebner\DataQueryBundle\Attribute\EntityAttribute\EntityAttributeInterface;
7+
use MalteHuebner\DataQueryBundle\Attribute\EntityAttribute\Queryable;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class DateTimeQueryableTest extends TestCase
11+
{
12+
public function testExtendsQueryable(): void
13+
{
14+
$attr = new DateTimeQueryable();
15+
16+
$this->assertInstanceOf(Queryable::class, $attr);
17+
}
18+
19+
public function testImplementsEntityAttributeInterface(): void
20+
{
21+
$attr = new DateTimeQueryable();
22+
23+
$this->assertInstanceOf(EntityAttributeInterface::class, $attr);
24+
}
25+
26+
public function testGetFormat(): void
27+
{
28+
$attr = new DateTimeQueryable(format: 'yyyy-MM-dd');
29+
30+
$this->assertSame('yyyy-MM-dd', $attr->getFormat());
31+
}
32+
33+
public function testGetPattern(): void
34+
{
35+
$attr = new DateTimeQueryable(pattern: 'Y-m-d');
36+
37+
$this->assertSame('Y-m-d', $attr->getPattern());
38+
}
39+
40+
public function testGetAccepts(): void
41+
{
42+
$attr = new DateTimeQueryable(accepts: ['year', 'month', 'day']);
43+
44+
$this->assertSame(['year', 'month', 'day'], $attr->getAccepts());
45+
}
46+
47+
public function testDefaultValues(): void
48+
{
49+
$attr = new DateTimeQueryable();
50+
51+
$this->assertSame([], $attr->getAccepts());
52+
$this->assertNull($attr->getFormat());
53+
$this->assertNull($attr->getPattern());
54+
}
55+
56+
public function testAllParameters(): void
57+
{
58+
$attr = new DateTimeQueryable(
59+
accepts: ['year'],
60+
format: 'yyyy-MM-dd',
61+
pattern: 'Y-m-d'
62+
);
63+
64+
$this->assertSame(['year'], $attr->getAccepts());
65+
$this->assertSame('yyyy-MM-dd', $attr->getFormat());
66+
$this->assertSame('Y-m-d', $attr->getPattern());
67+
}
68+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace MalteHuebner\DataQueryBundle\Tests\Attribute\EntityAttribute;
4+
5+
use MalteHuebner\DataQueryBundle\Attribute\AttributeInterface;
6+
use MalteHuebner\DataQueryBundle\Attribute\EntityAttribute\DefaultBooleanValue;
7+
use MalteHuebner\DataQueryBundle\Attribute\EntityAttribute\EntityAttributeInterface;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class DefaultBooleanValueTest extends TestCase
11+
{
12+
public function testImplementsAttributeInterface(): void
13+
{
14+
$attr = new DefaultBooleanValue();
15+
16+
$this->assertInstanceOf(AttributeInterface::class, $attr);
17+
}
18+
19+
public function testImplementsEntityAttributeInterface(): void
20+
{
21+
$attr = new DefaultBooleanValue();
22+
23+
$this->assertInstanceOf(EntityAttributeInterface::class, $attr);
24+
}
25+
26+
public function testDefaultValues(): void
27+
{
28+
$attr = new DefaultBooleanValue();
29+
30+
$this->assertNull($attr->getAlias());
31+
$this->assertFalse($attr->getValue());
32+
}
33+
34+
public function testGetAlias(): void
35+
{
36+
$attr = new DefaultBooleanValue(alias: 'myAlias');
37+
38+
$this->assertSame('myAlias', $attr->getAlias());
39+
}
40+
41+
public function testGetValueTrue(): void
42+
{
43+
$attr = new DefaultBooleanValue(value: true);
44+
45+
$this->assertTrue($attr->getValue());
46+
}
47+
48+
public function testGetValueFalse(): void
49+
{
50+
$attr = new DefaultBooleanValue(value: false);
51+
52+
$this->assertFalse($attr->getValue());
53+
}
54+
55+
public function testAllParameters(): void
56+
{
57+
$attr = new DefaultBooleanValue(alias: 'isActive', value: true);
58+
59+
$this->assertSame('isActive', $attr->getAlias());
60+
$this->assertTrue($attr->getValue());
61+
}
62+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace MalteHuebner\DataQueryBundle\Tests\Attribute\EntityAttribute;
4+
5+
use MalteHuebner\DataQueryBundle\Attribute\AttributeInterface;
6+
use MalteHuebner\DataQueryBundle\Attribute\EntityAttribute\EntityAttributeInterface;
7+
use MalteHuebner\DataQueryBundle\Attribute\EntityAttribute\Queryable;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class QueryableTest extends TestCase
11+
{
12+
public function testImplementsAttributeInterface(): void
13+
{
14+
$queryable = new Queryable();
15+
16+
$this->assertInstanceOf(AttributeInterface::class, $queryable);
17+
}
18+
19+
public function testImplementsEntityAttributeInterface(): void
20+
{
21+
$queryable = new Queryable();
22+
23+
$this->assertInstanceOf(EntityAttributeInterface::class, $queryable);
24+
}
25+
26+
public function testIsAttribute(): void
27+
{
28+
$reflectionClass = new \ReflectionClass(Queryable::class);
29+
$attributes = $reflectionClass->getAttributes(\Attribute::class);
30+
31+
$this->assertCount(1, $attributes);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace MalteHuebner\DataQueryBundle\Tests\Attribute\EntityAttribute;
4+
5+
use MalteHuebner\DataQueryBundle\Attribute\AttributeInterface;
6+
use MalteHuebner\DataQueryBundle\Attribute\EntityAttribute\EntityAttributeInterface;
7+
use MalteHuebner\DataQueryBundle\Attribute\EntityAttribute\Sortable;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class SortableTest extends TestCase
11+
{
12+
public function testImplementsAttributeInterface(): void
13+
{
14+
$sortable = new Sortable();
15+
16+
$this->assertInstanceOf(AttributeInterface::class, $sortable);
17+
}
18+
19+
public function testImplementsEntityAttributeInterface(): void
20+
{
21+
$sortable = new Sortable();
22+
23+
$this->assertInstanceOf(EntityAttributeInterface::class, $sortable);
24+
}
25+
26+
public function testIsAttribute(): void
27+
{
28+
$reflectionClass = new \ReflectionClass(Sortable::class);
29+
$attributes = $reflectionClass->getAttributes(\Attribute::class);
30+
31+
$this->assertCount(1, $attributes);
32+
}
33+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace MalteHuebner\DataQueryBundle\Tests\Attribute\ParameterAttribute;
4+
5+
use MalteHuebner\DataQueryBundle\Attribute\AttributeInterface;
6+
use MalteHuebner\DataQueryBundle\Attribute\ParameterAttribute\ParameterAttributeInterface;
7+
use MalteHuebner\DataQueryBundle\Attribute\ParameterAttribute\RequiredParameter;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class RequiredParameterTest extends TestCase
11+
{
12+
public function testImplementsAttributeInterface(): void
13+
{
14+
$attr = new RequiredParameter(parameterName: 'size');
15+
16+
$this->assertInstanceOf(AttributeInterface::class, $attr);
17+
}
18+
19+
public function testImplementsParameterAttributeInterface(): void
20+
{
21+
$attr = new RequiredParameter(parameterName: 'size');
22+
23+
$this->assertInstanceOf(ParameterAttributeInterface::class, $attr);
24+
}
25+
26+
public function testGetParameterName(): void
27+
{
28+
$attr = new RequiredParameter(parameterName: 'size');
29+
30+
$this->assertSame('size', $attr->getParameterName());
31+
}
32+
33+
public function testDifferentParameterNames(): void
34+
{
35+
$this->assertSame('orderBy', (new RequiredParameter(parameterName: 'orderBy'))->getParameterName());
36+
$this->assertSame('from', (new RequiredParameter(parameterName: 'from'))->getParameterName());
37+
$this->assertSame('orderDirection', (new RequiredParameter(parameterName: 'orderDirection'))->getParameterName());
38+
}
39+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace MalteHuebner\DataQueryBundle\Tests\Attribute\QueryAttribute;
4+
5+
use MalteHuebner\DataQueryBundle\Attribute\AttributeInterface;
6+
use MalteHuebner\DataQueryBundle\Attribute\QueryAttribute\QueryAttributeInterface;
7+
use MalteHuebner\DataQueryBundle\Attribute\QueryAttribute\RequiredEntityProperty;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class RequiredEntityPropertyTest extends TestCase
11+
{
12+
public function testImplementsAttributeInterface(): void
13+
{
14+
$attr = new RequiredEntityProperty(propertyName: 'pin');
15+
16+
$this->assertInstanceOf(AttributeInterface::class, $attr);
17+
}
18+
19+
public function testImplementsQueryAttributeInterface(): void
20+
{
21+
$attr = new RequiredEntityProperty(propertyName: 'pin');
22+
23+
$this->assertInstanceOf(QueryAttributeInterface::class, $attr);
24+
}
25+
26+
public function testGetPropertyName(): void
27+
{
28+
$attr = new RequiredEntityProperty(propertyName: 'dateTime');
29+
30+
$this->assertSame('dateTime', $attr->getPropertyName());
31+
}
32+
33+
public function testGetPropertyTypeDefaultNull(): void
34+
{
35+
$attr = new RequiredEntityProperty(propertyName: 'pin');
36+
37+
$this->assertNull($attr->getPropertyType());
38+
}
39+
40+
public function testGetPropertyType(): void
41+
{
42+
$attr = new RequiredEntityProperty(propertyName: 'pin', propertyType: 'string');
43+
44+
$this->assertSame('string', $attr->getPropertyType());
45+
}
46+
47+
public function testAllParameters(): void
48+
{
49+
$attr = new RequiredEntityProperty(propertyName: 'dateTime', propertyType: 'DateTime');
50+
51+
$this->assertSame('dateTime', $attr->getPropertyName());
52+
$this->assertSame('DateTime', $attr->getPropertyType());
53+
}
54+
}

0 commit comments

Comments
 (0)