Skip to content

Commit

Permalink
Rename trait to populate entity properties
Browse files Browse the repository at this point in the history
- Also fix multi repositories use case with no where
  query and only one repository
- Some configuration updates
  • Loading branch information
iquito committed Oct 15, 2020
1 parent a6a00ce commit 0594853
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 42 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"psalm_base": "vendor/bin/psalm --set-baseline=psalm-baseline.xml",
"phpunit": "vendor/bin/phpunit --colors=always",
"phpunit_clover": "vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml",
"codecoverage": "vendor/bin/phpunit --path-coverage --coverage-html tests/_reports",
"codecoverage": "vendor/bin/phpunit --coverage-html tests/_reports",
"phpcs": "vendor/bin/phpcs --standard=ruleset.xml --extensions=php --cache=.phpcs-cache --colors src",
"phpcsfix": "vendor/bin/phpcbf --standard=ruleset.xml --extensions=php --cache=.phpcs-cache src",
"binupdate": "@composer bin all update --ansi",
Expand Down
36 changes: 14 additions & 22 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/autoload.php"
>
<testsuites>
<testsuite name="Unit Tests">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">src</directory>
<exclude>
<directory>src/Generate/PHPFilesInDirectoryGetContents.php</directory>
</exclude>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="tests/autoload.php">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory>src/Generate/PHPFilesInDirectoryGetContents.php</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Unit Tests">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
5 changes: 3 additions & 2 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="3.14.2@3538fe1955d47f6ee926c0769d71af6db08aa488">
<files psalm-version="3.17.2@9e526d9cb569fe4631e6a737bbb7948d05596e3f">
<file src="src/MultiRepositoryReadOnly.php">
<MissingConstructor occurrences="1">
<MissingConstructor occurrences="2">
<code>$db</code>
<code>$db</code>
</MissingConstructor>
<PossiblyInvalidArgument occurrences="1">
Expand Down
8 changes: 6 additions & 2 deletions src/MultiRepositoryReadOnly.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,12 @@ protected function processOptions(array $validOptions, array $options, bool $wri
$sanitizedOptions['tables'] = \array_keys($sanitizedOptions['repositories']);
}

// WHERE needs some restrictions to glue the tables together
if (isset($validOptions['where']) && \count($sanitizedOptions['where']) === 0) {
// WHERE needs some restrictions to glue the tables together - except if there is only one repository
if (
isset($validOptions['where'])
&& \count($sanitizedOptions['where']) === 0
&& \count($sanitizedOptions['repositories']) > 1
) {
throw Debug::createException(
DBInvalidOptionException::class,
[MultiRepositoryReadOnlyInterface::class, BuilderInterface::class],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
/**
* @psalm-immutable
*/
trait EntityConstructorTrait
trait PopulatePropertiesWithIterableTrait
{
/**
* Initialize the object with an array - not used by repository, as the repository uses reflection to
* set entity values, but a constructor can be helpful for testing or other special/explicit usages
*
* @psalm-pure
*/
public function __construct(iterable $data = [])
{
Expand Down
4 changes: 2 additions & 2 deletions tests/TestEntities/NonRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Squirrel\Entities\Tests\TestEntities;

use Squirrel\Entities\EntityConstructorTrait;
use Squirrel\Entities\PopulatePropertiesWithIterableTrait;

class NonRepository
{
use EntityConstructorTrait;
use PopulatePropertiesWithIterableTrait;

/**
* @var int
Expand Down
4 changes: 2 additions & 2 deletions tests/TestEntities/NonRepositoryWithAnnotationInUse.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace Squirrel\Entities\Tests\TestEntities;

use Squirrel\Entities\Annotation as SQL;
use Squirrel\Entities\EntityConstructorTrait;
use Squirrel\Entities\PopulatePropertiesWithIterableTrait;

class NonRepositoryWithAnnotationInUse
{
use EntityConstructorTrait;
use PopulatePropertiesWithIterableTrait;

/**
* @var int
Expand Down
4 changes: 2 additions & 2 deletions tests/TestEntities/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace Squirrel\Entities\Tests\TestEntities;

use Squirrel\Entities\Annotation as SQL;
use Squirrel\Entities\EntityConstructorTrait;
use Squirrel\Entities\PopulatePropertiesWithIterableTrait;

/**
* @SQL\Entity("users")
*/
class User
{
use EntityConstructorTrait;
use PopulatePropertiesWithIterableTrait;

/**
* @SQL\Field("user_id", autoincrement=true)
Expand Down
4 changes: 2 additions & 2 deletions tests/TestEntities/UserAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

use Squirrel\Entities\Annotation\Entity;
use Squirrel\Entities\Annotation\Field;
use Squirrel\Entities\EntityConstructorTrait;
use Squirrel\Entities\PopulatePropertiesWithIterableTrait;

/**
* @Entity("users_address")
*/
class UserAddress
{
use EntityConstructorTrait;
use PopulatePropertiesWithIterableTrait;

/**
* @Field("user_id")
Expand Down
4 changes: 2 additions & 2 deletions tests/TestEntitiesInvalidBlob/UserAddressInvalid.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

use Squirrel\Entities\Annotation\Entity;
use Squirrel\Entities\Annotation\Field;
use Squirrel\Entities\EntityConstructorTrait;
use Squirrel\Entities\PopulatePropertiesWithIterableTrait;

/**
* @Entity("users_address")
*/
class UserAddressInvalid
{
use EntityConstructorTrait;
use PopulatePropertiesWithIterableTrait;

/**
* An integer field cannot be a blob: (only strings can be a blob)
Expand Down
4 changes: 2 additions & 2 deletions tests/TestEntitiesNoType/UserAddressInvalid.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

use Squirrel\Entities\Annotation\Entity;
use Squirrel\Entities\Annotation\Field;
use Squirrel\Entities\EntityConstructorTrait;
use Squirrel\Entities\PopulatePropertiesWithIterableTrait;

/**
* @Entity("users_address")
*/
class UserAddressInvalid
{
use EntityConstructorTrait;
use PopulatePropertiesWithIterableTrait;

/**
* No property type defined - we need this
Expand Down

0 comments on commit 0594853

Please sign in to comment.