Skip to content

Commit 91ebb5a

Browse files
SvenRtbgcweiske
authored andcommitted
Add autoload-dev and remove all require_once in tests
All non-namespaced classes in JsonMapperTest are made part of the PSR0 autoloading. Exception still made for the "Zoo" collection of classes.
1 parent 83b0e4f commit 91ebb5a

Some content is hidden

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

55 files changed

+44
-146
lines changed

composer.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
"autoload": {
66
"psr-0": {"JsonMapper": "src/"}
77
},
8+
"autoload-dev": {
9+
"psr-4": {
10+
"namespacetest\\": "tests/support/namespacetest",
11+
"othernamespace\\": "tests/support/othernamespace",
12+
"Enums\\": "tests/support/Enums"
13+
},
14+
"psr-0": {
15+
"JsonMapperTest_": "tests/support",
16+
"": ["tests/support/Zoo"]
17+
}
18+
},
819
"authors": [
920
{
1021
"name": "Christian Weiske",

tests/ArrayTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@
1313

1414
use namespacetest\model\MyArrayObject;
1515

16-
require_once 'JsonMapperTest/Array.php';
17-
require_once 'JsonMapperTest/ArrayAccessCollection.php';
18-
require_once 'JsonMapperTest/Broken.php';
19-
require_once 'JsonMapperTest/Simple.php';
20-
require_once 'JsonMapperTest/VariadicArray.php';
21-
require_once 'JsonMapperTest/Zoo/Animal.php';
22-
require_once 'JsonMapperTest/Zoo/Zoo.php';
23-
require_once 'JsonMapperTest/Zoo/Cat.php';
24-
require_once 'JsonMapperTest/Zoo/Fish.php';
25-
2616
/**
2717
* Unit tests for JsonMapper's array handling
2818
*

tests/Array_PHP74_Test.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,11 @@
1616
*/
1717
class Array_PHP74_Test extends TestCase
1818
{
19-
protected function setUp(): void
20-
{
21-
require_once 'JsonMapperTest/PHP74_Array.php';
22-
require_once 'JsonMapperTest/ArrayValueForStringProperty.php';
23-
}
24-
2519
public function testJsonMapper()
2620
{
2721
$json = json_decode('{"files": ["test.txt"]}');
2822
$jsonMapper = new \JsonMapper();
29-
$array = $jsonMapper->map($json, new PHP74_Array());
23+
$array = $jsonMapper->map($json, new JsonMapperTest_PHP74Array());
3024
self::assertCount(1, $array->files);
3125
}
3226

tests/Array_PHP80_Test.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@
1616
*/
1717
class Array_PHP80_Test extends TestCase
1818
{
19-
protected function setUp(): void
20-
{
21-
require_once 'JsonMapperTest/PHP80_Array.php';
22-
require_once 'JsonMapperTest/ArrayValueForStringProperty.php';
23-
}
24-
2519
public function testJsonMapper()
2620
{
2721
$json = json_decode('{"files": [{"value":"test.txt"}]}');
2822
$jsonMapper = new \JsonMapper();
2923
$jsonMapper->bIgnoreVisibility = true;
30-
$array = $jsonMapper->map($json, PHP80_Array::class);
24+
$array = $jsonMapper->map($json, JsonMapperTest_PHP80Array::class);
3125
self::assertCount(1, $array->getFiles());
3226
self::assertInstanceOf(JsonMapperTest_ArrayValueForStringProperty::class, $array->getFiles()[0]);
3327
}

tests/ClassMapTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
* @license OSL-3.0 http://opensource.org/licenses/osl-3.0
1111
* @link https://github.com/cweiske/jsonmapper
1212
*/
13-
require_once 'JsonMapperTest/Simple.php';
14-
require_once 'JsonMapperTest/Object.php';
15-
require_once 'JsonMapperTest/PlainObject.php';
16-
require_once 'JsonMapperTest/ValueObject.php';
17-
require_once 'JsonMapperTest/ComplexObject.php';
1813

1914
/**
2015
* Unit tests for JsonMapper's classMap

tests/Enums_PHP81_Test.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ class Enums_PHP81_Test extends \PHPUnit\Framework\TestCase
1616
{
1717
const TEST_DATA = '{"stringBackedEnum": "foo", "intBackedEnum": 2}';
1818

19-
protected function setUp(): void
20-
{
21-
require_once 'Enums/IntBackedEnum.php';
22-
require_once 'Enums/ObjectWithEnum.php';
23-
require_once 'Enums/StringBackedEnum.php';
24-
}
25-
2619
/**
2720
* Test for PHP8.1 enums.
2821
*/

tests/EventTest.php

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

1414
use PHPUnit\Framework\TestCase;
1515

16-
require_once 'JsonMapperTest/EventObject.php';
17-
1816
/**
1917
* Unit tests for JsonMapper's object handling (events)
2018
*

tests/JsonMapperTest/PrivateWithSetterSub.php

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/MixedType_PHP80_Test.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@ class MixedType_PHP80_Test extends \PHPUnit\Framework\TestCase
1515
const TEST_DATA_COMPLEX = '{"data": { "id": 123, "name": "Test User" }}';
1616
const TEST_DATA_SIMPLE = '{"data": 123}';
1717

18-
/**
19-
* Sets up test cases loading required classes.
20-
*
21-
* This is in setUp and not at the top of this file to ensure this is only
22-
* executed with PHP 8.0 (due to the `@requires` tag).
23-
*/
24-
protected function setUp(): void
25-
{
26-
require_once 'namespacetest/PhpMixedType.php';
27-
}
28-
2918
/**
3019
* Test for PHP 8.0 mixed type containing an object.
3120
*/

tests/NameMappingTest.php

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

55
use PHPUnit\Framework\TestCase;
66

7-
require_once 'JsonMapperTest/Simple.php';
8-
97
class NameMappingTest extends TestCase
108
{
119
public function testItSetKeysIfReturnedByUndefinedPropertyHandler(): void

tests/namespacetest/NamespaceTest.php renamed to tests/NamespaceTest.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
<?php
2-
namespace namespacetest;
3-
require_once __DIR__ . '/Unit.php';
4-
require_once __DIR__ . '/UnitData.php';
5-
require_once __DIR__ . '/model/MyArrayObject.php';
6-
require_once __DIR__ . '/model/User.php';
7-
require_once __DIR__ . '/model/UserList.php';
8-
require_once __DIR__ . '/../othernamespace/Foo.php';
2+
3+
use namespacetest\UnitData;
94

105
class NamespaceTest extends \PHPUnit\Framework\TestCase
116
{

tests/ObjectTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@
1010
* @license OSL-3.0 http://opensource.org/licenses/osl-3.0
1111
* @link https://github.com/cweiske/jsonmapper
1212
*/
13-
require_once 'JsonMapperTest/Simple.php';
14-
require_once 'JsonMapperTest/Object.php';
15-
require_once 'JsonMapperTest/PlainObject.php';
16-
require_once 'JsonMapperTest/ValueObject.php';
17-
require_once 'JsonMapperTest/ComplexObject.php';
18-
require_once 'JsonMapperTest/ObjectConstructor.php';
19-
require_once 'JsonMapperTest/ObjectConstructorOptional.php';
2013

2114
/**
2215
* Unit tests for JsonMapper's object handling

tests/Object_PHP71_Test.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,6 @@
2323
*/
2424
class Object_PHP71_Test extends \PHPUnit\Framework\TestCase
2525
{
26-
/**
27-
* Sets up test cases loading required classes.
28-
*
29-
* This is in setUp and not at the top of this file to ensure this is only
30-
* executed with PHP 7.1 (due to the `@requires` tag).
31-
*/
32-
protected function setUp(): void
33-
{
34-
require_once 'JsonMapperTest/PlainObject.php';
35-
require_once 'JsonMapperTest/PHP7_Object.php';
36-
}
3726
/**
3827
* Test for PHP7 nullable types like "?Object"
3928
*/
@@ -42,7 +31,7 @@ public function testObjectSetterTypeNullable()
4231
$jm = new JsonMapper();
4332
$sn = $jm->map(
4433
json_decode('{"typeNullableObject":null}'),
45-
new JsonMapperTest_PHP7_Object()
34+
new JsonMapperTest_PHP7Object()
4635
);
4736
$this->assertNull($sn->typeNullableObject);
4837
}
@@ -53,11 +42,11 @@ public function testObjectSetterTypeNullable()
5342
public function testObjectSetterDocblockInvalidNull()
5443
{
5544
$this->expectException(JsonMapper_Exception::class);
56-
$this->expectExceptionMessage('JSON property "nonNullableObject" in class "JsonMapperTest_PHP7_Object" must not be NULL');
45+
$this->expectExceptionMessage('JSON property "nonNullableObject" in class "JsonMapperTest_PHP7Object" must not be NULL');
5746
$jm = new JsonMapper();
5847
$sn = $jm->map(
5948
json_decode('{"nonNullableObject":null}'),
60-
new JsonMapperTest_PHP7_Object()
49+
new JsonMapperTest_PHP7Object()
6150
);
6251
}
6352
}

tests/OtherTest.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@
99
* @license OSL-3.0 http://opensource.org/licenses/osl-3.0
1010
* @link http://cweiske.de/
1111
*/
12-
require_once 'JsonMapperTest/Broken.php';
13-
require_once 'JsonMapperTest/DependencyInjector.php';
14-
require_once 'JsonMapperTest/Simple.php';
15-
require_once 'JsonMapperTest/Logger.php';
16-
require_once 'JsonMapperTest/PrivateWithSetter.php';
17-
require_once 'JsonMapperTest/PrivateWithSetterSub.php';
18-
require_once 'JsonMapperTest/ValueObject.php';
1912

2013
/**
2114
* Unit tests for JsonMapper that don't fit in other categories
@@ -210,7 +203,7 @@ public function testPrivatePropertyWithPublicSetter()
210203
$jm->setLogger($logger);
211204

212205
$json = '{"privateProperty" : 1}';
213-
$result = $jm->map(json_decode($json), new PrivateWithSetter());
206+
$result = $jm->map(json_decode($json), new JsonMapperTest_PrivateWithSetter());
214207

215208
$this->assertEquals(1, $result->getPrivateProperty());
216209
$this->assertTrue(empty($logger->log));
@@ -219,14 +212,14 @@ public function testPrivatePropertyWithPublicSetter()
219212
public function testPrivatePropertyWithNoSetter()
220213
{
221214
$this->expectException(JsonMapper_Exception::class);
222-
$this->expectExceptionMessage('JSON property "privateNoSetter" has no public setter method in object of type PrivateWithSetter');
215+
$this->expectExceptionMessage('JSON property "privateNoSetter" has no public setter method in object of type JsonMapperTest_PrivateWithSetter');
223216
$jm = new JsonMapper();
224217
$jm->bExceptionOnUndefinedProperty = true;
225218
$logger = new JsonMapperTest_Logger();
226219
$jm->setLogger($logger);
227220

228221
$json = '{"privateNoSetter" : 1}';
229-
$result = $jm->map(json_decode($json), new PrivateWithSetter());
222+
$result = $jm->map(json_decode($json), new JsonMapperTest_PrivateWithSetter());
230223

231224
$this->assertEquals(1, $result->getPrivateProperty());
232225
$this->assertTrue(empty($logger->log));
@@ -238,7 +231,7 @@ public function testPrivatePropertyWithNoSetterButAllowed()
238231
$jm->bIgnoreVisibility = true;
239232

240233
$json = '{"privateNoSetter" : 1}';
241-
$result = $jm->map(json_decode($json), new PrivateWithSetter());
234+
$result = $jm->map(json_decode($json), new JsonMapperTest_PrivateWithSetter());
242235

243236
$this->assertEquals(1, $result->getPrivateNoSetter());
244237
}
@@ -249,22 +242,22 @@ public function testPrivatePropertyInParentClassWithNoSetterButAllowed()
249242
$jm->bIgnoreVisibility = true;
250243

251244
$json = '{"privateNoSetter" : 1}';
252-
$result = $jm->map(json_decode($json), new PrivateWithSetterSub());
245+
$result = $jm->map(json_decode($json), new JsonMapperTest_PrivateWithSetterSub());
253246

254247
$this->assertEquals(1, $result->getPrivateNoSetter());
255248
}
256249

257250
public function testPrivatePropertyWithPrivateSetter()
258251
{
259252
$this->expectException(JsonMapper_Exception::class);
260-
$this->expectExceptionMessage('JSON property "privatePropertyPrivateSetter" has no public setter method in object of type PrivateWithSetter');
253+
$this->expectExceptionMessage('JSON property "privatePropertyPrivateSetter" has no public setter method in object of type JsonMapperTest_PrivateWithSetter');
261254
$jm = new JsonMapper();
262255
$jm->bExceptionOnUndefinedProperty = true;
263256
$logger = new JsonMapperTest_Logger();
264257
$jm->setLogger($logger);
265258

266259
$json = '{"privatePropertyPrivateSetter" : 1}';
267-
$result = $jm->map(json_decode($json), new PrivateWithSetter());
260+
$result = $jm->map(json_decode($json), new JsonMapperTest_PrivateWithSetter());
268261
}
269262

270263
public function testPrivatePropertySetterWithoutDoc()
@@ -277,7 +270,7 @@ public function testPrivatePropertySetterWithoutDoc()
277270
$jm->bExceptionOnUndefinedProperty = true;
278271
$jm->setLogger(new JsonMapperTest_Logger());
279272

280-
$result = $jm->map(json_decode('{"privatePropertySetterWithoutDoc" : 1}'), new PrivateWithSetter());
273+
$result = $jm->map(json_decode('{"privatePropertySetterWithoutDoc" : 1}'), new JsonMapperTest_PrivateWithSetter());
281274
$this->assertEquals(1, $result->getPrivatePropertySetterWithoutDoc());
282275
}
283276

@@ -291,7 +284,7 @@ public function testPrivatePropertyNullableNotNullSetterWithoutDoc()
291284
$jm->bExceptionOnUndefinedProperty = true;
292285
$jm->setLogger(new JsonMapperTest_Logger());
293286

294-
$result = $jm->map(json_decode('{"privatePropertyNullableSetterWithoutDoc" : 1}'), new PrivateWithSetter());
287+
$result = $jm->map(json_decode('{"privatePropertyNullableSetterWithoutDoc" : 1}'), new JsonMapperTest_PrivateWithSetter());
295288
$this->assertSame(1, $result->getPrivatePropertyNullableSetterWithoutDoc());
296289
}
297290

@@ -305,7 +298,7 @@ public function testPrivatePropertyNullableNullSetterWithoutDoc()
305298
$jm->bExceptionOnUndefinedProperty = true;
306299
$jm->setLogger(new JsonMapperTest_Logger());
307300

308-
$result = $jm->map(json_decode('{"privatePropertyNullableSetterWithoutDoc" : null}'), new PrivateWithSetter());
301+
$result = $jm->map(json_decode('{"privatePropertyNullableSetterWithoutDoc" : null}'), new JsonMapperTest_PrivateWithSetter());
309302
$this->assertNull($result->getPrivatePropertyNullableSetterWithoutDoc());
310303
}
311304

@@ -319,7 +312,7 @@ public function testPrivateArrayOfSimple()
319312
json_decode(
320313
'{"privateArrayOfSimple" : [{"pbool": true, "pint": 42}, {"pbool": false, "pint": 24}]}'
321314
),
322-
new PrivateWithSetter()
315+
new JsonMapperTest_PrivateWithSetter()
323316
);
324317

325318
$a = new JsonMapperTest_Simple;
@@ -343,7 +336,7 @@ public function testPrivateSetterButAllowed()
343336
$jm->bExceptionOnUndefinedProperty = true;
344337

345338
$json = '{"privateSetter" : 1}';
346-
$result = $jm->map(json_decode($json), new PrivateWithSetter());
339+
$result = $jm->map(json_decode($json), new JsonMapperTest_PrivateWithSetter());
347340

348341
$this->assertEquals(1, $result->getPrivateSetter());
349342
}

tests/Options/RemoveUndefinedAttributesTest.php renamed to tests/RemoveUndefinedAttributesTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* @license OSL-3.0 http://opensource.org/licenses/osl-3.0
1010
* @link http://cweiske.de/
1111
*/
12-
require_once __DIR__ . '/../JsonMapperTest/Simple.php';
1312

1413
/**
1514
* Unit tests for JsonMapper option "bRemoveUndefinedAttributes".

tests/SimpleTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* @license OSL-3.0 http://opensource.org/licenses/osl-3.0
1111
* @link https://github.com/cweiske/jsonmapper
1212
*/
13-
require_once 'JsonMapperTest/Simple.php';
1413

1514
/**
1615
* Unit tests for JsonMapper's simple type handling

tests/StrictTypes_PHP74_Test.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,6 @@ class StrictTypes_PHP74_Test extends \PHPUnit\Framework\TestCase
1414
{
1515
const TEST_DATA = '{"id": 123, "importedNs": {"name": "Name"}, "otherNs": {"name": "Foo"}, "withoutType": "anything", "docDefinedType": {"name": "Name"}, "nullable": "value", "fooArray": [{"name": "Foo 1"}, {"name": "Foo 2"}]}';
1616

17-
/**
18-
* Sets up test cases loading required classes.
19-
*
20-
* This is in setUp and not at the top of this file to ensure this is only
21-
* executed with PHP 7.4 (due to the `@requires` tag).
22-
*/
23-
protected function setUp(): void
24-
{
25-
require_once 'namespacetest/PhpStrictTypes.php';
26-
require_once 'namespacetest/model/User.php';
27-
require_once 'othernamespace/Foo.php';
28-
}
29-
3017
/**
3118
* Test for PHP7.4 strict types.
3219
*/

tests/UnionTypesTest.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@
1212
*/
1313
class UnionTypesTest extends \PHPUnit\Framework\TestCase
1414
{
15-
/**
16-
* Sets up test cases loading required classes.
17-
*
18-
* This is in setUp and not at the top of this file to ensure this is only
19-
* executed with PHP 8.0 (due to the `@requires` tag).
20-
*/
21-
protected function setUp(): void
22-
{
23-
require_once 'JsonMapperTest/UnionTypes.php';
24-
}
25-
2615
/**
2716
* Test for "public DateTime|string $dateOrStringNative"
2817
*/

tests/bootstrap.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
<?php
2-
if (is_dir(__DIR__ . '/../src/')) {
3-
set_include_path(
4-
__DIR__ . '/../src/'
5-
. PATH_SEPARATOR . get_include_path()
6-
);
7-
}
8-
require_once 'JsonMapper.php';
9-
require_once 'JsonMapper/Exception.php';
2+
require __DIR__ . '/../vendor/autoload.php';
3+
104
?>
File renamed without changes.

0 commit comments

Comments
 (0)