Skip to content

Commit c7fadf4

Browse files
committed
Merge branch 'release/2.0.0'
2 parents ac925f2 + 748d769 commit c7fadf4

File tree

6 files changed

+29
-11
lines changed

6 files changed

+29
-11
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ matrix:
1616
- php: 7.4
1717
- php: 7.4
1818
env: COMPOSER_UPDATE_FLAGS='--prefer-lowest --prefer-stable'
19+
- php: 8.0
20+
- php: 8.0
21+
env: COMPOSER_UPDATE_FLAGS='--prefer-lowest --prefer-stable'
1922

2023
# Ignore the platform requirements for the upcoming PHP version
2124
- php: nightly
@@ -32,6 +35,7 @@ branches:
3235
only:
3336
- master
3437
- develop
38+
- 2.x
3539

3640
install:
3741
- curl -s http://getcomposer.org/installer | php

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [2.0.0]
10+
## Changed
11+
- Update to version ^2.0 JsonMapper and LaravelPackage
12+
### Added
13+
- Add PHP8 support to the build matrix. [PR#4](https://github.com/JsonMapper/EloquentMiddleware/pull/4)
14+
915
## [1.0.0] - 2020-09-03
1016
### Added
1117
- Allow Eloquent models to be populated from Json.

Version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0
1+
2.0.0

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,22 @@
1919
},
2020
"autoload-dev": {
2121
"psr-4": {
22-
"JsonMapper\\EloquentMiddleware\\Tests\\": "tests/"
22+
"JsonMapper\\EloquentMiddleware\\Tests\\": "tests/",
23+
"JsonMapper\\Tests\\": "vendor/json-mapper/json-mapper/tests/"
2324
}
2425
},
2526
"require": {
26-
"json-mapper/laravel-package": "^1.1",
27+
"json-mapper/laravel-package": "^2.0",
2728
"php": "^7.2 || ^8.0",
2829
"doctrine/dbal": "^2.3",
29-
"json-mapper/json-mapper": "^1.1"
30+
"json-mapper/json-mapper": "^2.0"
3031
},
3132
"require-dev": {
3233
"squizlabs/php_codesniffer": "^3.5",
3334
"phpstan/phpstan": "^0.12.19",
3435
"php-coveralls/php-coveralls": "^2.2",
3536
"orchestra/testbench": "^5.3",
36-
"phpunit/phpunit": "^8.0|^9.0"
37+
"phpunit/phpunit": "^8.5 || ^9.0"
3738
},
3839
"scripts": {
3940
"phpcs": "phpcs --standard=PSR12 src tests --ignore=tests/database",

src/EloquentMiddleware.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use JsonMapper\JsonMapperInterface;
1212
use JsonMapper\Middleware\AbstractMiddleware;
1313
use JsonMapper\ValueObjects\PropertyMap;
14+
use JsonMapper\ValueObjects\PropertyType;
1415
use JsonMapper\Wrapper\ObjectWrapper;
1516
use Psr\SimpleCache\CacheInterface;
1617

@@ -131,10 +132,9 @@ protected function discoverPropertiesFromTable(Model $model, PropertyMap $proper
131132

132133
$property = PropertyBuilder::new()
133134
->setName($name)
134-
->setType($type)
135+
->addType($type, false)
135136
->setIsNullable(!$column->getNotnull())
136137
->setVisibility(Visibility::PUBLIC())
137-
->setIsArray(false)
138138
->build();
139139
$propertyMap->addProperty($property);
140140
}
@@ -188,7 +188,7 @@ protected function discoverPropertiesCasts(Model $model, PropertyMap $propertyMa
188188
$realType = $this->checkForCustomLaravelCasts($realType);
189189

190190
$builder = $propertyMap->getProperty($name)->asBuilder();
191-
$property = $builder->setType($realType)->build();
191+
$property = $builder->setTypes(new PropertyType($realType, false))->build();
192192
$propertyMap->addProperty($property);
193193
}
194194
}

tests/Unit/EloquentMiddlewareTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,25 @@
88
use Doctrine\DBAL\Schema\AbstractSchemaManager;
99
use Doctrine\DBAL\Schema\Column;
1010
use Doctrine\DBAL\Types\Type;
11-
use Doctrine\DBAL\Types\Types;
1211
use Illuminate\Database\Connection;
1312
use Illuminate\Database\Eloquent\Model;
1413
use JsonMapper\Cache\NullCache;
1514
use JsonMapper\EloquentMiddleware\EloquentMiddleware;
15+
use JsonMapper\Enums\Visibility;
1616
use JsonMapper\JsonMapperInterface;
17+
use JsonMapper\Tests\Helpers\AssertThatPropertyTrait;
1718
use JsonMapper\ValueObjects\PropertyMap;
1819
use JsonMapper\Wrapper\ObjectWrapper;
1920
use Orchestra\Testbench\TestCase;
2021

2122
class EloquentMiddlewareTest extends TestCase
2223
{
24+
use AssertThatPropertyTrait;
25+
2326
/**
2427
* @covers \JsonMapper\EloquentMiddleware\EloquentMiddleware
2528
*/
26-
public function testNonEloquentModelRetunsEmptyPropertyMap(): void
29+
public function testNonEloquentModelReturnsEmptyPropertyMap(): void
2730
{
2831
$middleware = new EloquentMiddleware(new NullCache());
2932
$propertyMap = new PropertyMap();
@@ -47,7 +50,11 @@ public function testColumnsFromTheDatabaseAreReturned(): void
4750
$middleware->handle(new \stdClass(), new ObjectWrapper($model), $propertyMap, $mapper);
4851

4952
self::assertTrue($propertyMap->hasProperty('id'));
50-
self::assertEquals('integer', $propertyMap->getProperty('id')->getType());
53+
$this->assertThatProperty($propertyMap->getProperty('id'))
54+
->hasName('id')
55+
->onlyHasType('integer', false)
56+
->hasVisibility(Visibility::PUBLIC())
57+
->isNotNullable();
5158
}
5259

5360
private function prepareMockedModel(Column ...$columns): Model

0 commit comments

Comments
 (0)