Skip to content

Commit 61ff474

Browse files
jenkins-botGerrit Code Review
authored andcommitted
Merge "GQL: Add architecture tests for the reuse domain"
2 parents baaa84a + edf918c commit 61ff474

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed

extension-repo.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@
957957
"Wikibase\\Repo\\Tests\\Domains\\Crud\\": "repo/domains/crud/tests/phpunit/",
958958
"Wikibase\\Repo\\Tests\\Domains\\Crud\\Architecture\\": "repo/domains/crud/tests/architecture/",
959959
"Wikibase\\Repo\\Tests\\Domains\\Reuse\\": "repo/domains/reuse/tests/phpunit/",
960+
"Wikibase\\Repo\\Tests\\Domains\\Reuse\\Architecture\\": "repo/domains/reuse/tests/architecture/",
960961
"Wikibase\\Lib\\Tests\\": "lib/tests/phpunit/",
961962
"Wikibase\\Lib\\Tests\\Unit\\": "lib/tests/phpunit/unit/",
962963
"Wikibase\\Lib\\Tests\\Changes\\": "lib/packages/wikibase/changes/tests/",

phpstan.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ services:
77
class: Wikibase\Repo\Tests\Domains\Search\Architecture\ArchitectureTest
88
tags:
99
- phpat.test
10+
-
11+
class: Wikibase\Repo\Tests\Domains\Reuse\Architecture\ArchitectureTest
12+
tags:
13+
- phpat.test
1014
-
1115
class: Wikibase\Repo\Tests\Architecture\ArchitectureTest
1216
tags:
@@ -26,6 +30,8 @@ parameters:
2630
- ./repo/domains/crud/tests/architecture/
2731
- ./repo/domains/search/src/
2832
- ./repo/domains/search/tests/architecture/
33+
- ./repo/domains/reuse/src/
34+
- ./repo/domains/reuse/tests/architecture/
2935
- ./repo/rest-api/src/
3036
- ./repo/rest-api/tests/architecture/
3137

prpl-ruleset.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<element key="repo/domains/crud/tests/architecture" value="Wikibase\Repo\Tests\Domains\Crud\Architecture"/>
4040
<element key="repo/domains/reuse/src" value="Wikibase\Repo\Domains\Reuse"/>
4141
<element key="repo/domains/reuse/tests/phpunit" value="Wikibase\Repo\Tests\Domains\Reuse"/>
42+
<element key="repo/domains/reuse/tests/architecture" value="Wikibase\Repo\Tests\Domains\Reuse\Architecture"/>
4243
</property>
4344
</properties>
4445
</rule>
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php declare( strict_types=1 );
2+
3+
namespace Wikibase\Repo\Tests\Domains\Reuse\Architecture;
4+
5+
use PHPat\Selector\Selector;
6+
use PHPat\Test\Builder\Rule;
7+
use PHPat\Test\PHPat;
8+
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup;
9+
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookupException;
10+
use Wikibase\DataModel\Services\Statement\StatementGuidParser;
11+
12+
/**
13+
* @coversNothing
14+
*
15+
* @license GPL-2.0-or-later
16+
*/
17+
class ArchitectureTest {
18+
19+
private const REUSE_DOMAIN = 'Wikibase\Repo\Domains\Reuse';
20+
private const DOMAIN_MODEL = self::REUSE_DOMAIN . '\Domain\Model';
21+
private const DOMAIN_SERVICES = self::REUSE_DOMAIN . '\Domain\Services';
22+
private const USE_CASES = self::REUSE_DOMAIN . '\Application\UseCases';
23+
24+
public function testDomainModel(): Rule {
25+
return PHPat::rule()
26+
->classes( Selector::inNamespace( self::DOMAIN_MODEL ) )
27+
->canOnlyDependOn()
28+
->classes( ...$this->allowedDomainModelDependencies() );
29+
}
30+
31+
/**
32+
* Domain models may depend on:
33+
* - DataModel namespaces containing entities and their parts
34+
* - other classes from their own namespace
35+
*/
36+
private function allowedDomainModelDependencies(): array {
37+
return [
38+
...$this->dataModelNamespaces(),
39+
Selector::inNamespace( self::DOMAIN_MODEL ),
40+
];
41+
}
42+
43+
public function testDomainServices(): Rule {
44+
return PHPat::rule()
45+
->classes( Selector::inNamespace( self::DOMAIN_SERVICES ) )
46+
->canOnlyDependOn()
47+
->classes( ...$this->allowedDomainServicesDependencies() );
48+
}
49+
50+
/**
51+
* Domain services may depend on:
52+
* - the domain models namespace and everything it depends on
53+
* - some hand-picked DataModel services
54+
* - other classes from their own namespace
55+
*/
56+
private function allowedDomainServicesDependencies(): array {
57+
return [
58+
...$this->allowedDomainModelDependencies(),
59+
...$this->allowedDataModelServices(),
60+
Selector::inNamespace( self::DOMAIN_SERVICES ),
61+
];
62+
}
63+
64+
public function testUseCases(): Rule {
65+
return PHPat::rule()
66+
->classes( Selector::inNamespace( self::USE_CASES ) )
67+
->canOnlyDependOn()
68+
->classes( ...$this->allowedUseCasesDependencies() );
69+
}
70+
71+
/**
72+
* Use cases may depend on:
73+
* - the domain services namespace and everything it depends on
74+
* - other classes from their own namespace
75+
*/
76+
private function allowedUseCasesDependencies(): array {
77+
return [
78+
...$this->allowedDomainServicesDependencies(),
79+
Selector::inNamespace( self::USE_CASES ),
80+
];
81+
}
82+
83+
private function allowedDataModelServices(): array {
84+
return [
85+
Selector::classname( PropertyDataTypeLookup::class ),
86+
Selector::classname( PropertyDataTypeLookupException::class ),
87+
Selector::classname( StatementGuidParser::class ),
88+
];
89+
}
90+
91+
private function dataModelNamespaces(): array {
92+
return [
93+
// These are listed in such a complicated way so that only DataModel entities and their parts are allowed without the
94+
// namespaces nested within DataModel like e.g. Wikibase\DataModel\Serializers.
95+
...array_map(
96+
fn( string $escapedNamespace ) => Selector::classname(
97+
'/^' . preg_quote( $escapedNamespace ) . '\\\\\w+$/',
98+
true
99+
),
100+
[
101+
'Wikibase\DataModel',
102+
'Wikibase\DataModel\Entity',
103+
'Wikibase\DataModel\Exception',
104+
'Wikibase\DataModel\Snak',
105+
'Wikibase\DataModel\Statement',
106+
'Wikibase\DataModel\Term',
107+
]
108+
),
109+
Selector::inNamespace( 'DataValues' ),
110+
];
111+
}
112+
113+
}

repo/tests/architecture/ArchitectureTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ private function allowedCrossDomainClasses(): array {
6868
Selector::inNamespace( self::REGEX_DOMAIN_READMODEL, true ),
6969
// search domain models (we don't have readmodels there)
7070
Selector::inNamespace( 'Wikibase\Repo\Domains\Search\Domain\Model' ),
71+
// reuse domain models (we don't have readmodels there)
72+
Selector::inNamespace( 'Wikibase\Repo\Domains\Reuse\Domain\Model' ),
7173
];
7274
}
7375

0 commit comments

Comments
 (0)