Skip to content

Commit bf432f9

Browse files
committed
Refactored LanguageServiceTest and added stricter validation for LanguageCreateStruct
1 parent ad27abb commit bf432f9

File tree

5 files changed

+37
-250
lines changed

5 files changed

+37
-250
lines changed

phpstan-baseline.neon

Lines changed: 2 additions & 224 deletions
Original file line numberDiff line numberDiff line change
@@ -23292,60 +23292,6 @@ parameters:
2329223292
count: 1
2329323293
path: tests/integration/Core/Repository/BaseTestCase.php
2329423294

23295-
-
23296-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertPropertiesCorrect\(\) has no return type specified\.$#'
23297-
identifier: missingType.return
23298-
count: 1
23299-
path: tests/integration/Core/Repository/BaseTestCase.php
23300-
23301-
-
23302-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertPropertiesCorrectUnsorted\(\) has no return type specified\.$#'
23303-
identifier: missingType.return
23304-
count: 1
23305-
path: tests/integration/Core/Repository/BaseTestCase.php
23306-
23307-
-
23308-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertPropertiesEqual\(\) has no return type specified\.$#'
23309-
identifier: missingType.return
23310-
count: 1
23311-
path: tests/integration/Core/Repository/BaseTestCase.php
23312-
23313-
-
23314-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertPropertiesEqual\(\) has parameter \$actualValue with no type specified\.$#'
23315-
identifier: missingType.parameter
23316-
count: 1
23317-
path: tests/integration/Core/Repository/BaseTestCase.php
23318-
23319-
-
23320-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertPropertiesEqual\(\) has parameter \$expectedValue with no type specified\.$#'
23321-
identifier: missingType.parameter
23322-
count: 1
23323-
path: tests/integration/Core/Repository/BaseTestCase.php
23324-
23325-
-
23326-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertPropertiesEqual\(\) has parameter \$propertyName with no type specified\.$#'
23327-
identifier: missingType.parameter
23328-
count: 1
23329-
path: tests/integration/Core/Repository/BaseTestCase.php
23330-
23331-
-
23332-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertPropertiesEqual\(\) has parameter \$sortArray with no type specified\.$#'
23333-
identifier: missingType.parameter
23334-
count: 1
23335-
path: tests/integration/Core/Repository/BaseTestCase.php
23336-
23337-
-
23338-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertStructPropertiesCorrect\(\) has no return type specified\.$#'
23339-
identifier: missingType.return
23340-
count: 1
23341-
path: tests/integration/Core/Repository/BaseTestCase.php
23342-
23343-
-
23344-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:assertStructPropertiesCorrect\(\) has parameter \$additionalProperties with no value type specified in iterable type array\.$#'
23345-
identifier: missingType.iterableValue
23346-
count: 1
23347-
path: tests/integration/Core/Repository/BaseTestCase.php
23348-
2334923295
-
2335023296
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:createFolder\(\) has parameter \$names with no value type specified in iterable type array\.$#'
2335123297
identifier: missingType.iterableValue
@@ -23388,48 +23334,18 @@ parameters:
2338823334
count: 1
2338923335
path: tests/integration/Core/Repository/BaseTestCase.php
2339023336

23391-
-
23392-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:sortItems\(\) has no return type specified\.$#'
23393-
identifier: missingType.return
23394-
count: 1
23395-
path: tests/integration/Core/Repository/BaseTestCase.php
23396-
23397-
-
23398-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:sortItems\(\) has parameter \$items with no value type specified in iterable type array\.$#'
23399-
identifier: missingType.iterableValue
23400-
count: 1
23401-
path: tests/integration/Core/Repository/BaseTestCase.php
23402-
2340323337
-
2340423338
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:updateFolder\(\) has parameter \$names with no value type specified in iterable type array\.$#'
2340523339
identifier: missingType.iterableValue
2340623340
count: 1
2340723341
path: tests/integration/Core/Repository/BaseTestCase.php
2340823342

23409-
-
23410-
message: '#^PHPDoc tag @param references unknown parameter\: \$propertyNames$#'
23411-
identifier: parameter.notFound
23412-
count: 1
23413-
path: tests/integration/Core/Repository/BaseTestCase.php
23414-
2341523343
-
2341623344
message: '#^PHPDoc tag @var for variable \$searchHandler contains unknown class Ibexa\\Solr\\Handler\.$#'
2341723345
identifier: class.notFound
2341823346
count: 1
2341923347
path: tests/integration/Core/Repository/BaseTestCase.php
2342023348

23421-
-
23422-
message: '#^Parameter \#1 \$string1 of function strcmp expects string, bool\|float\|int\|string given\.$#'
23423-
identifier: argument.type
23424-
count: 1
23425-
path: tests/integration/Core/Repository/BaseTestCase.php
23426-
23427-
-
23428-
message: '#^Parameter \#2 \$string2 of function strcmp expects string, bool\|float\|int\|string given\.$#'
23429-
identifier: argument.type
23430-
count: 1
23431-
path: tests/integration/Core/Repository/BaseTestCase.php
23432-
2343323349
-
2343423350
message: '#^Property Ibexa\\Tests\\Integration\\Core\\Repository\\BaseTestCase\:\:\$repository \(Ibexa\\Contracts\\Core\\Repository\\Repository\) does not accept null\.$#'
2343523351
identifier: assign.propertyType
@@ -31663,146 +31579,8 @@ parameters:
3166331579
path: tests/integration/Core/Repository/LanguageServiceMaximumSupportedLanguagesTest.php
3166431580

3166531581
-
31666-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Language'' and Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Language will always evaluate to true\.$#'
31667-
identifier: staticMethod.alreadyNarrowedType
31668-
count: 3
31669-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31670-
31671-
-
31672-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\LanguageCreateStruct'' and Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\LanguageCreateStruct will always evaluate to true\.$#'
31673-
identifier: staticMethod.alreadyNarrowedType
31674-
count: 1
31675-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31676-
31677-
-
31678-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:loadLanguagesReturnsAnEmptyArrayByDefault\(\) has no return type specified\.$#'
31679-
identifier: missingType.return
31680-
count: 1
31681-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31682-
31683-
-
31684-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testCreateLanguageInTransactionWithCommit\(\) has no return type specified\.$#'
31685-
identifier: missingType.return
31686-
count: 1
31687-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31688-
31689-
-
31690-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testCreateLanguageInTransactionWithRollback\(\) has no return type specified\.$#'
31691-
identifier: missingType.return
31692-
count: 1
31693-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31694-
31695-
-
31696-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testCreateLanguageSetsExpectedProperties\(\) has no return type specified\.$#'
31697-
identifier: missingType.return
31698-
count: 1
31699-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31700-
31701-
-
31702-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testCreateLanguageSetsIdPropertyOnReturnedLanguage\(\) has no return type specified\.$#'
31703-
identifier: missingType.return
31704-
count: 1
31705-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31706-
31707-
-
31708-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testCreateLanguageThrowsInvalidArgumentException\(\) has no return type specified\.$#'
31709-
identifier: missingType.return
31710-
count: 1
31711-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31712-
31713-
-
31714-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testDeleteLanguage\(\) has no return type specified\.$#'
31715-
identifier: missingType.return
31716-
count: 1
31717-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31718-
31719-
-
31720-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testDeleteLanguageThrowsInvalidArgumentException\(\) has no return type specified\.$#'
31721-
identifier: missingType.return
31722-
count: 1
31723-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31724-
31725-
-
31726-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testDisableLanguage\(\) has no return type specified\.$#'
31727-
identifier: missingType.return
31728-
count: 1
31729-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31730-
31731-
-
31732-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testEnableLanguage\(\) has no return type specified\.$#'
31733-
identifier: missingType.return
31734-
count: 1
31735-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31736-
31737-
-
31738-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testGetDefaultLanguageCode\(\) has no return type specified\.$#'
31739-
identifier: missingType.return
31740-
count: 1
31741-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31742-
31743-
-
31744-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testLoadLanguage\(\) has no return type specified\.$#'
31745-
identifier: missingType.return
31746-
count: 1
31747-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31748-
31749-
-
31750-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testLoadLanguageById\(\) has no return type specified\.$#'
31751-
identifier: missingType.return
31752-
count: 1
31753-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31754-
31755-
-
31756-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testLoadLanguageByIdThrowsNotFoundException\(\) has no return type specified\.$#'
31757-
identifier: missingType.return
31758-
count: 1
31759-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31760-
31761-
-
31762-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testLoadLanguageThrowsInvalidArgumentException\(\) has no return type specified\.$#'
31763-
identifier: missingType.return
31764-
count: 1
31765-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31766-
31767-
-
31768-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testLoadLanguageThrowsNotFoundException\(\) has no return type specified\.$#'
31769-
identifier: missingType.return
31770-
count: 1
31771-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31772-
31773-
-
31774-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testLoadLanguages\(\) has no return type specified\.$#'
31775-
identifier: missingType.return
31776-
count: 1
31777-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31778-
31779-
-
31780-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testNewLanguageCreateStruct\(\) has no return type specified\.$#'
31781-
identifier: missingType.return
31782-
count: 1
31783-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31784-
31785-
-
31786-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testUpdateLanguageName\(\) has no return type specified\.$#'
31787-
identifier: missingType.return
31788-
count: 1
31789-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31790-
31791-
-
31792-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testUpdateLanguageNameInTransactionWithCommit\(\) has no return type specified\.$#'
31793-
identifier: missingType.return
31794-
count: 1
31795-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31796-
31797-
-
31798-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testUpdateLanguageNameInTransactionWithRollback\(\) has no return type specified\.$#'
31799-
identifier: missingType.return
31800-
count: 1
31801-
path: tests/integration/Core/Repository/LanguageServiceTest.php
31802-
31803-
-
31804-
message: '#^Method Ibexa\\Tests\\Integration\\Core\\Repository\\LanguageServiceTest\:\:testUpdateLanguageNameThrowsInvalidArgumentException\(\) has no return type specified\.$#'
31805-
identifier: missingType.return
31582+
message: '#^Argument of an invalid type Ibexa\\Contracts\\Core\\Repository\\Values\\ValueObject supplied for foreach, only iterables are supported\.$#'
31583+
identifier: foreach.nonIterable
3180631584
count: 1
3180731585
path: tests/integration/Core/Repository/LanguageServiceTest.php
3180831586

tests/integration/Core/CoreTestKernel.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?php
22

3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
38
namespace Ibexa\Tests\Integration\Core;
49

510
use Ibexa\Contracts\Core\Test\IbexaTestKernel;

tests/integration/Core/Repository/AssertPropertiesTrait.php

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
namespace Ibexa\Tests\Integration\Core\Repository;
99

10+
use ArrayObject;
11+
use DateTime;
12+
use DateTimeInterface;
1013
use Ibexa\Contracts\Core\Repository\Values\ValueObject;
1114

1215
trait AssertPropertiesTrait
@@ -22,17 +25,17 @@ protected function assertPropertiesCorrect(array $expectedValues, ValueObject $a
2225
{
2326
foreach ($expectedValues as $propertyName => $propertyValue) {
2427
if ($propertyValue instanceof ValueObject) {
25-
$this->assertStructPropertiesCorrect($propertyValue, $actualObject->$propertyName);
28+
self::assertStructPropertiesCorrect($propertyValue, $actualObject->$propertyName);
2629
} elseif (is_array($propertyValue)) {
2730
foreach ($propertyValue as $key => $value) {
2831
if ($value instanceof ValueObject) {
29-
$this->assertStructPropertiesCorrect($value, $actualObject->$propertyName[$key]);
32+
self::assertStructPropertiesCorrect($value, $actualObject->$propertyName[$key]);
3033
} else {
31-
$this->assertPropertiesEqual("$propertyName\[$key\]", $value, $actualObject->$propertyName[$key]);
34+
self::assertPropertiesEqual("$propertyName\[$key\]", $value, $actualObject->$propertyName[$key]);
3235
}
3336
}
3437
} else {
35-
$this->assertPropertiesEqual($propertyName, $propertyValue, $actualObject->$propertyName);
38+
self::assertPropertiesEqual($propertyName, $propertyValue, $actualObject->$propertyName);
3639
}
3740
}
3841
}
@@ -52,9 +55,9 @@ protected function assertPropertiesCorrectUnsorted(array $expectedValues, ValueO
5255
{
5356
foreach ($expectedValues as $propertyName => $propertyValue) {
5457
if ($propertyValue instanceof ValueObject) {
55-
$this->assertStructPropertiesCorrect($propertyValue, $actualObject->$propertyName);
58+
self::assertStructPropertiesCorrect($propertyValue, $actualObject->$propertyName);
5659
} else {
57-
$this->assertPropertiesEqual($propertyName, $propertyValue, $actualObject->$propertyName, true);
60+
self::assertPropertiesEqual($propertyName, $propertyValue, $actualObject->$propertyName, true);
5861
}
5962
}
6063
}
@@ -66,21 +69,21 @@ protected function assertPropertiesCorrectUnsorted(array $expectedValues, ValueO
6669
*
6770
* @param array<string> $additionalProperties
6871
*/
69-
protected function assertStructPropertiesCorrect(
72+
protected static function assertStructPropertiesCorrect(
7073
ValueObject $expectedValues,
7174
ValueObject $actualObject,
7275
array $additionalProperties = [],
7376
): void {
7477
foreach ($expectedValues as $propertyName => $propertyValue) {
7578
if ($propertyValue instanceof ValueObject) {
76-
$this->assertStructPropertiesCorrect($propertyValue, $actualObject->$propertyName);
79+
self::assertStructPropertiesCorrect($propertyValue, $actualObject->$propertyName);
7780
} else {
78-
$this->assertPropertiesEqual($propertyName, $propertyValue, $actualObject->$propertyName);
81+
self::assertPropertiesEqual($propertyName, $propertyValue, $actualObject->$propertyName);
7982
}
8083
}
8184

8285
foreach ($additionalProperties as $propertyName) {
83-
$this->assertPropertiesEqual($propertyName, $expectedValues->$propertyName, $actualObject->$propertyName);
86+
self::assertPropertiesEqual($propertyName, $expectedValues->$propertyName, $actualObject->$propertyName);
8487
}
8588
}
8689

@@ -89,34 +92,38 @@ protected function assertStructPropertiesCorrect(
8992
*
9093
* @see \Ibexa\Tests\Integration\Core\Repository\BaseTestCase::assertPropertiesCorrectUnsorted
9194
*/
92-
private function sortItems(array &$items): void
95+
private static function sortItems(array &$items): void
9396
{
9497
$sorter = static function ($a, $b): int {
9598
if (!is_scalar($a) || !is_scalar($b)) {
9699
self::fail('Wrong usage: method ' . __METHOD__ . ' accepts only an array of scalar values');
97100
}
98101

99-
return strcmp($a, $b);
102+
return strcmp((string)$a, (string)$b);
100103
};
101104
usort($items, $sorter);
102105
}
103106

104-
private function assertPropertiesEqual($propertyName, $expectedValue, $actualValue, $sortArray = false): void
105-
{
106-
if ($expectedValue instanceof \ArrayObject) {
107+
private static function assertPropertiesEqual(
108+
string $propertyName,
109+
mixed $expectedValue,
110+
mixed $actualValue,
111+
bool $sortArray = false
112+
): void {
113+
if ($expectedValue instanceof ArrayObject) {
107114
$expectedValue = $expectedValue->getArrayCopy();
108-
} elseif ($expectedValue instanceof \DateTimeInterface) {
109-
$expectedValue = $expectedValue->format(\DateTime::RFC850);
115+
} elseif ($expectedValue instanceof DateTimeInterface) {
116+
$expectedValue = $expectedValue->format(DateTime::RFC850);
110117
}
111-
if ($actualValue instanceof \ArrayObject) {
118+
if ($actualValue instanceof ArrayObject) {
112119
$actualValue = $actualValue->getArrayCopy();
113-
} elseif ($actualValue instanceof \DateTimeInterface) {
114-
$actualValue = $actualValue->format(\DateTime::RFC850);
120+
} elseif ($actualValue instanceof DateTimeInterface) {
121+
$actualValue = $actualValue->format(DateTime::RFC850);
115122
}
116123

117124
if ($sortArray && is_array($actualValue) && is_array($expectedValue)) {
118-
$this->sortItems($actualValue);
119-
$this->sortItems($expectedValue);
125+
self::sortItems($actualValue);
126+
self::sortItems($expectedValue);
120127
}
121128

122129
self::assertEquals(

0 commit comments

Comments
 (0)