Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhard-efler committed Apr 13, 2021
2 parents ce7ccc3 + 6efc533 commit a478742
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 77 deletions.
10 changes: 6 additions & 4 deletions .travis.yml
Expand Up @@ -2,23 +2,25 @@ language: php
sudo: false

php:
- "7.1"
- "7.2"
- "7.3"
- "7.4"
- "8.0"

cache:
directories:
- $HOME/.composer/cache

install:
- if [ $TRAVIS_PHP_VERSION = '7.2' ] || [ $TRAVIS_PHP_VERSION = '7.3' ]; then composer self-update --1 --no-progress --no-interaction; fi
- composer install --prefer-dist --no-interaction

script:
- if [ $TRAVIS_PHP_VERSION = '7.2' ]; then vendor/bin/phpunit --coverage-clover build/clover.xml; else vendor/bin/phpunit; fi
- if [ $TRAVIS_PHP_VERSION = '7.2' ]; then vendor/bin/php-cs-fixer fix --config=vendor/ixocreate/coding-standard/.php_cs -v --diff --dry-run --using-cache=no; fi
- if [ $TRAVIS_PHP_VERSION = '7.4' ]; then XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-clover build/clover.xml; else vendor/bin/phpunit; fi
- if [ $TRAVIS_PHP_VERSION = '7.4' ]; then vendor/bin/php-cs-fixer fix --config=vendor/ixocreate/coding-standard/.php_cs -v --diff --dry-run --using-cache=no; fi

after_success:
- if [ $TRAVIS_PHP_VERSION = '7.2' ]; then php vendor/bin/php-coveralls -v -x build/clover.xml -o build/clover.json; fi
- if [ $TRAVIS_PHP_VERSION = '7.4' ]; then php vendor/bin/php-coveralls -v -x build/clover.xml -o build/clover.json; fi

notifications:
email: false
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
@@ -1,6 +1,10 @@
# Release Notes

## [Unreleased](https://github.com/ixocreate/entity-package/compare/0.2.5...develop)
## [Unreleased](https://github.com/ixocreate/entity-package/compare/0.3.0...develop)

## [v0.3.0 (2021-01-21)](https://github.com/ixocreate/event-package/compare/0.2.5...0.3.0)
### Update
- Update to Application 0.3

## [v0.2.5 (2019-09-17)](https://github.com/ixocreate/entity-package/compare/0.2.4...0.2.5)
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/EntityBench.php
Expand Up @@ -5,7 +5,7 @@

use DateTime;
use Ixocreate\Application\Service\ServiceManagerConfig;
use Ixocreate\Application\Service\ServiceManagerConfigurator;
use Ixocreate\Application\ServiceManager\ServiceManagerConfigurator;
use Ixocreate\Schema\Type\DateTimeType;
use Ixocreate\Schema\Type\Type;
use Ixocreate\Schema\Type\TypeInterface;
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/standalone.php
@@ -1,7 +1,7 @@
<?php

use Ixocreate\Application\Service\ServiceManagerConfig;
use Ixocreate\Application\Service\ServiceManagerConfigurator;
use Ixocreate\Application\ServiceManager\ServiceManagerConfigurator;
use Ixocreate\Benchmark\Cms\TestEntity;
use Ixocreate\Benchmark\Cms\TypeFactory;
use Ixocreate\Schema\Type\DateTimeType;
Expand Down
14 changes: 8 additions & 6 deletions composer.json
Expand Up @@ -11,16 +11,18 @@
"role": "Developer"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^7.1",
"ixocreate/application": "^0.2",
"ixocreate/collection": "^0.1",
"ixocreate/schema-package": "^0.2",
"zendframework/zend-filter": "^2.7"
"php": "^7.2 || ^8.0",
"ixocreate/application": "^0.3.0",
"ixocreate/collection": "^0.2",
"ixocreate/schema-package": "^0.3.0",
"laminas/laminas-filter": "^2.7"
},
"require-dev": {
"ixocreate/coding-standard": "^2.0",
"ixocreate/test": "dev-develop",
"ixocreate/test": "^0.2",
"phpbench/phpbench": "@dev"
},
"autoload": {
Expand Down
11 changes: 7 additions & 4 deletions src/EntityTrait.php
Expand Up @@ -112,7 +112,7 @@ private function applyData(array $data) : void
continue;
}

throw new PropertyNotFoundException(\sprintf("Property '%s' not found in '%s'", $definition->getName(), \get_class($this)));
throw new PropertyNotFoundException(\sprintf("Invalid property '%s' in '%s'. Value must not be null", $definition->getName(), \get_class($this)));
}
if (!empty($data)) {
foreach (\array_keys($data) as $name) {
Expand All @@ -125,9 +125,12 @@ private function applyValue(Definition $definition, $value): void
{
$name = $definition->getName();

if ($value === null && $definition->isNullAble()) {
$this->{$name} = null;
return;
if ($value === null) {
if ($definition->isNullAble()) {
$this->{$name} = null;
return;
}
throw new InvalidPropertyException(\sprintf("Invalid property '%s' in '%s'. Value must not be null", $name, \get_class($this)));
}

if (self::$prototypes[$name]['type'] === 'internal') {
Expand Down
52 changes: 6 additions & 46 deletions src/Package.php
Expand Up @@ -9,48 +9,16 @@

namespace Ixocreate\Entity;

use Ixocreate\Application\Configurator\ConfiguratorRegistryInterface;
use Ixocreate\Application\Package\PackageInterface;
use Ixocreate\Application\Service\ServiceRegistryInterface;
use Ixocreate\ServiceManager\ServiceManagerInterface;

final class Package implements PackageInterface
{
/**
* @param ConfiguratorRegistryInterface $configuratorRegistry
* @return array
*/
public function configure(ConfiguratorRegistryInterface $configuratorRegistry): void
{
}

/**
* @param ServiceRegistryInterface $serviceRegistry
*/
public function addServices(ServiceRegistryInterface $serviceRegistry): void
{
}

/**
* @return array|null
*/
public function getBootstrapItems(): ?array
{
return null;
}

/**
* @return array|null
*/
public function getConfigProvider(): ?array
{
return null;
}

/**
* @param ServiceManagerInterface $serviceManager
*/
public function boot(ServiceManagerInterface $serviceManager): void
public function getBootstrapItems(): array
{
return [];
}

/**
Expand All @@ -62,18 +30,10 @@ public function getBootstrapDirectory(): ?string
}

/**
* @return null|string
* @return array
*/
public function getConfigDirectory(): ?string
public function getDependencies(): array
{
return null;
}

/**
* @return array|null
*/
public function getDependencies(): ?array
{
return null;
return [];
}
}
16 changes: 16 additions & 0 deletions tests/src/Entity/DefinitionTest.php
Expand Up @@ -40,4 +40,20 @@ public function testDefaultDefinitionValues()
$this->assertTrue($definition->isNullAble());
$this->assertTrue($definition->isPublic());
}

public function testDefaultCallback()
{
$definition = new Definition(
'testString',
'string',
true,
true,
true,
function () {
return 'testDefault';
}
);

$this->assertEquals('testDefault', $definition->getDefault());
}
}
17 changes: 17 additions & 0 deletions tests/src/Entity/EntityCollectionTest.php
Expand Up @@ -59,6 +59,23 @@ public function testCollection()
$this->assertSame($data, $collection->toArray());
}

public function testIndexBy()
{
$data = $this->data();
$collection = new EntityCollection($data, 'id');

$indexData = [
$data[0]->id => $data[0],
$data[1]->id => $data[1],
$data[2]->id => $data[2],
$data[3]->id => $data[3],
$data[4]->id => $data[4],
];

$this->assertSame(5, $collection->count());
$this->assertSame($indexData, $collection->toArray());
}

public function testInvalidTypeException()
{
$this->expectException(InvalidType::class);
Expand Down
129 changes: 129 additions & 0 deletions tests/src/Entity/EntityTraitTest.php
Expand Up @@ -19,6 +19,7 @@
use Ixocreate\Schema\Element\ColorElement;
use Ixocreate\Schema\Element\TextElement;
use Ixocreate\Schema\Type\ColorType;
use Ixocreate\Schema\Type\Exception\InvalidTypeException;
use Ixocreate\Schema\Type\Type;
use Ixocreate\Schema\Type\TypeInterface;
use Ixocreate\ServiceManager\Exception\ServiceNotFoundException;
Expand Down Expand Up @@ -70,6 +71,36 @@ protected static function createDefinitions() : DefinitionCollection
$this->assertSame("somethingelse", $newMock->name);
}

public function testInvalidType()
{
$this->expectException(InvalidTypeException::class);

$data = [
'name' => [],
'type' => 1,
'category' => 2,
];

$mock = new class($data) implements EntityInterface {
use EntityTrait;

private $name;

private $type;

private $category;

protected static function createDefinitions() : DefinitionCollection
{
return new DefinitionCollection([
new Definition("name", TypeInterface::TYPE_STRING, false),
new Definition("type", TypeInterface::TYPE_INT, true),
new Definition("category", TypeInterface::TYPE_INT, false, true, true, 1),
]);
}
};
}

/**
* @runInSeparateProcess
*/
Expand Down Expand Up @@ -191,6 +222,28 @@ protected static function createDefinitions() : DefinitionCollection
};
}

public function testNotNullProperty()
{
$this->expectException(InvalidPropertyException::class);

$data = [
'name' => null,
];

new class($data) implements EntityInterface {
use EntityTrait;

private $name;

protected static function createDefinitions() : DefinitionCollection
{
return new DefinitionCollection([
new Definition('name', TypeInterface::TYPE_STRING, false),
]);
}
};
}

public function testEmptyException()
{
$this->expectException(PropertyNotFoundException::class);
Expand Down Expand Up @@ -272,4 +325,80 @@ protected static function createDefinitions() : DefinitionCollection

$mock->with("test", "test");
}

public function testToPublicArray()
{
$data = [
'name' => 'testName',
'fieldPrivate' => 'topSecret',
'field2' => 'someValue',
];

$entity = new class($data) implements EntityInterface {
use EntityTrait;

private $name;

private $fieldPrivate;

private $field2;

protected static function createDefinitions() : DefinitionCollection
{
return new DefinitionCollection([
new Definition('name', TypeInterface::TYPE_STRING, false, true),
new Definition('fieldPrivate', TypeInterface::TYPE_STRING, false, false),
new Definition('field2', TypeInterface::TYPE_STRING, false, true),
]);
}
};

unset($data['fieldPrivate']);

$this->assertEquals($data, $entity->toPublicArray());
$this->assertEquals($data, $entity->jsonSerialize());
}

public function testInvalidArrayAccess()
{
$this->expectException(InvalidPropertyException::class);

$entity = $this->getSimpleEntity();

$value = $entity['invalidProperty'];
}

public function testArrayAccessSet()
{
$this->expectException(\BadMethodCallException::class);

$entity = $this->getSimpleEntity();

$entity['name'] = 'newName';
}

public function testArrayAccessUnset()
{
$this->expectException(\BadMethodCallException::class);

$entity = $this->getSimpleEntity();

unset($entity['name']);
}

private function getSimpleEntity(): EntityInterface
{
return new class(['name' => 'someName']) implements EntityInterface {
use EntityTrait;

private $name;

protected static function createDefinitions() : DefinitionCollection
{
return new DefinitionCollection([
new Definition('name', TypeInterface::TYPE_STRING, false),
]);
}
};
}
}

0 comments on commit a478742

Please sign in to comment.