Skip to content

Commit

Permalink
2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Falseclock committed Apr 17, 2022
1 parent 99ff386 commit 5462dc8
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 32 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: PHP

on:
push:
branches:
- master
pull_request:
types:
- opened
- reopened
- edited
- synchronize

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress

# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
# Docs: https://getcomposer.org/doc/articles/scripts.md

- name: Run test suite
#run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml
run: vendor/bin/phpunit
working-directory: './'

#- name: Build coverage report
# env:
# COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
# run: vendor/bin/php-coveralls --verbose --coverage_clover=build/logs/clover.xm
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ vendor/*
/phpunit
/build/
/.phpunit.cache/
/.run/

6 changes: 6 additions & 0 deletions .run/DBD-PHP-Entity.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="DBD-PHP-Entity" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
<TestRunner configuration_file="$PROJECT_DIR$/phpunit.xml" directory="$PROJECT_DIR$/tests" use_alternative_configuration_file="true" />
<method v="2" />
</configuration>
</component>
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"myclabs/php-enum": "^1.7.7"
},
"require-dev": {
"phpunit/phpunit": "^9.5.0",
"php-coveralls/php-coveralls": "^2.4.3"
"phpunit/phpunit": "^9.5.20",
"php-coveralls/php-coveralls": "^2.5.2"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/DBD/Entity/Common/Enforcer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function __add($class, $c)
$constantsForced = $reflection->getConstants();
foreach ($constantsForced as $constant => $value) {
if (constant("$c::$constant") == "abstract") {
trigger_error("Undefined constant $constant in " . (string)$c, E_USER_ERROR);
trigger_error(sprintf("Undefined constant %s in %s", $constant, $c), E_USER_ERROR);
}
}
} catch (ReflectionException $e) {
Expand Down
2 changes: 1 addition & 1 deletion src/DBD/Entity/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Constraint
*/
public function __construct(?array $constraintParams = null)
{
if (isset($constraintParams) and is_array($constraintParams)) {
if (is_array($constraintParams)) {
foreach ($constraintParams as $key => $value) {
$this->$key = $value;
}
Expand Down
4 changes: 2 additions & 2 deletions src/DBD/Entity/Embedded.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class Embedded
public const DB_TYPE = "embeddedDbType";
public const ENTITY_CLASS = "embeddedEntityClass";
public const IS_ITERABLE = "embeddedIsIterable";
/** @var string set to FALSE if you want avoid exceptions for Strictly Filled Entity */
/** @var string set to FALSE if you want to avoid exceptions for Strictly Filled Entity */
public const NAME = "embeddedName";
/**
* Set to FALSE if you don't gonna pass data, but wont set data manually, or calculate in postProcessing
* Set to FALSE if you are not going to pass data, but won't set data manually, or calculate in postProcessing
* @see Entity::postProcessing()
* @var string $name name of the columns in view or selected with AS.
*/
Expand Down
10 changes: 6 additions & 4 deletions src/DBD/Entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private function setBaseColumns(Mapper $mapper)
}

/** Note: Function names are case-insensitive, though it is usually good form to call functions as they appear in their declaration. */
$setterMethod = "set{$property}";
$setterMethod = sprintf("set%s", $property);

/** @var Column $fieldDefinition */
$fieldDefinition = $mapper->$property;
Expand All @@ -282,7 +282,7 @@ private function setBaseColumns(Mapper $mapper)
} else {
/**
* Entity public variables should not have default values.
* But some times we need to have default value for column in case of $rowData has null value
* But sometimes we need to have default value for column in case of $rowData has null value
* In this case we should not override default value if $columnValue is null
*/
if (!isset($this->$property) and isset($columnValue)) {
Expand Down Expand Up @@ -379,7 +379,7 @@ private function setComplex(Mapper $map, int $maxLevels, int $currentLevel)

/**
* If entity data should be modified after setModelData, create same function in Entity.
* For example it is heavy cost to aggregate some data in SQL side, any more cost efficient will do that with PHP
* For example, it is heavy cost to aggregate some data in SQL side, any more cost-efficient will do that with PHP
*
* @see Embedded::$name
* @see setModelData()
Expand Down Expand Up @@ -429,6 +429,8 @@ public function __get(string $methodName)
throw new EntityException(sprintf("Can't find property or getter method for '\$%s' of '%s'", $methodName, get_class($this)));
}

return $this->$lookupMethod();
$this->$methodName = $this->$lookupMethod();

return $this->$methodName;
}
}
11 changes: 0 additions & 11 deletions src/DBD/Entity/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,17 +362,6 @@ public static function meWithoutEnforcer(): Mapper
return self::instantiate(false);
}

/**
* @return mixed
* @deprecated
* @see Mapper::getColumns()
* @todo Remove in 2.4 version
*/
public function getBaseColumns()
{
return MapperCache::me()->baseColumns[$this->name()];
}

/**
* Special getter to access protected and private properties
* @param string $property
Expand Down
7 changes: 0 additions & 7 deletions src/DBD/Entity/MapperCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ class MapperCache extends Singleton
{
/** @var array $allVariables */
public $allVariables = [];
/**
* @var array $baseColumns
* @deprecated
* @see MapperCache::$columns
* @todo Remove in 2.4 version
*/
public $baseColumns = [];
/** @var array $columns */
public $columns = [];
/** @var array $complex */
Expand Down
42 changes: 42 additions & 0 deletions tests/DBD/Entity/Tests/Entities/DeclarationChain/E.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/********************************************************************************
* Apache License, Version 2.0 *
* *
* Copyright [2020] [Nurlan Mukhanov <[email protected]>] *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
********************************************************************************/

namespace DBD\Entity\Tests\Entities\DeclarationChain;

use DBD\Entity\Interfaces\OnlyDeclaredPropertiesEntity;

/**
* @property bool $a4
*/
class E extends D implements OnlyDeclaredPropertiesEntity
{
/**
* @return bool
*/
public function getA4()
{
return true;
}
}

class EMap extends DMap
{

}
17 changes: 14 additions & 3 deletions tests/DBD/Entity/Tests/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use DBD\Entity\Tests\Entities\DeclarationChain\B;
use DBD\Entity\Tests\Entities\DeclarationChain\C;
use DBD\Entity\Tests\Entities\DeclarationChain\D;
use DBD\Entity\Tests\Entities\DeclarationChain\E;
use DBD\Entity\Tests\Entities\JsonTypeColumn;
use DBD\Entity\Tests\Entities\JsonTypeColumnMap;
use DBD\Entity\Tests\Entities\PersonBase;
Expand Down Expand Up @@ -109,7 +110,6 @@ public function testDeclarationChain3()

// but calling this property should trigger exception
self::assertTrue(isset($d->$name));
$d->$name;
}
}

Expand All @@ -133,7 +133,7 @@ public function testDeclarationChain2()
self::assertObjectHasAttribute($missingProperty, $c);

// but calling this property should trigger exception
self::assertFalse(isset($c->$missingProperty), "C class still has property '{$missingProperty}'");
self::assertFalse(isset($c->$missingProperty), "C class still has property '$missingProperty'");

// Undefined property: DBD\Entity\Tests\Entities\DeclarationChain\B::$a3
$this->expectException(EntityException::class);
Expand All @@ -142,6 +142,17 @@ public function testDeclarationChain2()
$c->$missingProperty;
}

/**
* @return void
* @throws EntityException
*/
public function testDeclaration() {
$e = new E(Data::getDeclarationChainData());

$result = $e->a4;

self::assertTrue($result);
}
/**
* @throws EntityException
*/
Expand Down Expand Up @@ -347,7 +358,7 @@ public function testSetters()
}

/**
* Case when we selecting a lot of fields and forget to select some of them for FullEntity or StrictlyFilledEntity
* Case when we're selecting a lot of fields and forget to select some of them for FullEntity or StrictlyFilledEntity
* @throws EntityException
* @noinspection PhpExpressionResultUnusedInspection
*/
Expand Down

0 comments on commit 5462dc8

Please sign in to comment.