Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.0.2-alpha -> master #4

Merged
merged 4 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/simple-entities-run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Execute the Test Cases
on:
push:
branches: [master]
branches: [master, 0.0.2-alpha]
jobs:
setup:
runs-on: ubuntu-20.04
Expand All @@ -18,3 +18,5 @@ jobs:
run: composer install --prefer-dist --no-progress -vvv
- name: Run Test cases
run: composer run tests
- name: Run PHPStan
run: composer run phpstan
695 changes: 674 additions & 21 deletions LICENSE

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
},
"minimum-stability": "stable",
"require-dev": {
"phpunit/phpunit": "9.5.x-dev"
"phpunit/phpunit": "9.5.x-dev",
"phpstan/phpstan": "^1.8"
},
"scripts": {
"tests": "./vendor/bin/phpunit --colors test/"
"tests": "./vendor/bin/phpunit --colors test/",
"phpstan": "./vendor/bin/phpstan analyse src test"
}
}
63 changes: 61 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parameters:
level: 0
ignoreErrors:
4 changes: 2 additions & 2 deletions src/Entity/BaseEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private function getFieldTypesInstance($strict_type = false) {
* @param string $name
* The name of the field.
*/
abstract public function isSingleValued($name);
abstract public function isSingleValuedField($name);

/**
* @{inheritdoc}
Expand All @@ -69,7 +69,7 @@ public function parse($instance, $strict_type = false) {
* @{inheritdoc}
*/
public function parseField($name, $field) {
if ($this->isSingleValued($name)) {
if ($this->isSingleValuedField($name)) {
return $this->resolveDefaultFields($field);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function __construct() {
/**
* @{inheritdoc}
*/
public function isSingleValued($name) {
public function isSingleValuedField($name) {
return in_array($name, [
'fid',
'uuid',
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function __construct() {
/**
* @{inheritdoc}
*/
public function isSingleValued($name) {
public function isSingleValuedField($name) {
return in_array($name, [
'nid',
'uuid',
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function __construct() {
/**
* @{inheritdoc}
*/
public function isSingleValued($name) {
public function isSingleValuedField($name) {
return in_array($name, [
'tid',
'uuid',
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function __construct() {
/**
* @{inheritdoc}
*/
public function isSingleValued($name) {
public function isSingleValuedField($name) {
return in_array($name, [
'uid',
'uuid',
Expand Down
5 changes: 3 additions & 2 deletions src/FieldTypes/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace DrupalUtils\EntityConvert\FieldTypes;

use DrupalUtils\EntityConvert\EntityConvertFactory;

use DrupalUtils\EntityConvert\Entity\File;
use DrupalUtils\EntityConvert\Entity\Image;

use Drupal\file\Entity\File as DrupalFile;

Expand Down Expand Up @@ -34,6 +33,7 @@ public function get_entity_reference($value) {
* @return mixed
*/
public function get_file($value) {
/** @phpstan-ignore-next-line */
$file = DrupalFile::load($value['target_id']);
$parsedEntity = (new File())->parse($file);
return $parsedEntity->toArray();
Expand All @@ -48,6 +48,7 @@ public function get_file($value) {
* @return mixed
*/
public function get_image($value) {
/** @phpstan-ignore-next-line */
$file = DrupalFile::load($value['target_id']);
$parsedEntity = (new File())->parse($file);
return $parsedEntity->toArray();
Expand Down
12 changes: 6 additions & 6 deletions test/Entity/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ class FileTest extends TestCase {

public function testFieldSingleValue() {
$file = new File();
$this->assertTrue($file->isSingleValued('fid'));
$this->assertTrue($file->isSingleValued('uri'));
$this->assertTrue($file->isSingleValued('uuid'));
$this->assertFalse($file->isSingleValued('name'));
$this->assertTrue($file->isSingleValuedField('fid'));
$this->assertTrue($file->isSingleValuedField('uri'));
$this->assertTrue($file->isSingleValuedField('uuid'));
$this->assertFalse($file->isSingleValuedField('name'));
}

public function testFileMockObject() {
$mockedFileInstance = new Entity('file', 'fid');
$sea = new EntityConvert();
$parsedFile = $sea->toArray($mockedFileInstance);
$ec = new EntityConvert();
$parsedFile = $ec->toArray($mockedFileInstance);
$this->assertArrayHasKey('fid', $parsedFile);
$this->assertSame(PHP_INT_MAX, $parsedFile['fid']);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Entity/Mock/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Entity {
/**
* Type of entity node, taxonomy, user, file.
*/
protected $entityTypeId;
protected $getEntityTypeId;

/**
* The field corresponding to the entity.
Expand Down
12 changes: 6 additions & 6 deletions test/Entity/NodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ class NodeTest extends TestCase {

public function testFieldSingleValue() {
$node = new Node();
$this->assertTrue($node->isSingleValued('nid'));
$this->assertTrue($node->isSingleValued('type'));
$this->assertTrue($node->isSingleValued('uuid'));
$this->assertFalse($node->isSingleValued('uuiid'));
$this->assertTrue($node->isSingleValuedField('nid'));
$this->assertTrue($node->isSingleValuedField('type'));
$this->assertTrue($node->isSingleValuedField('uuid'));
$this->assertFalse($node->isSingleValuedField('uuiid'));
}

public function testNodeMockObject() {
$mockedNodeInstance = new Entity('node', 'nid');
$sea = new EntityConvert();
$parsedNode = $sea->toArray($mockedNodeInstance);
$ec = new EntityConvert();
$parsedNode = $ec->toArray($mockedNodeInstance);
$this->assertArrayHasKey('nid', $parsedNode);
$this->assertSame(PHP_INT_MAX, $parsedNode['nid']);
}
Expand Down
12 changes: 6 additions & 6 deletions test/Entity/TaxonomyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ class TaxonomyTest extends TestCase {

public function testFieldSingleValue() {
$taxonomy = new Taxonomy();
$this->assertTrue($taxonomy->isSingleValued('tid'));
$this->assertTrue($taxonomy->isSingleValued('vid'));
$this->assertTrue($taxonomy->isSingleValued('uuid'));
$this->assertFalse($taxonomy->isSingleValued('nid'));
$this->assertTrue($taxonomy->isSingleValuedField('tid'));
$this->assertTrue($taxonomy->isSingleValuedField('vid'));
$this->assertTrue($taxonomy->isSingleValuedField('uuid'));
$this->assertFalse($taxonomy->isSingleValuedField('nid'));
}

public function testTaxonomyMockObject() {
$mockedTaxonomyInstance = new Entity('taxonomy_term', 'tid');
$sea = new EntityConvert();
$parsedTaxonomy = $sea->toArray($mockedTaxonomyInstance);
$ec = new EntityConvert();
$parsedTaxonomy = $ec->toArray($mockedTaxonomyInstance);
$this->assertArrayHasKey('tid', $parsedTaxonomy);
$this->assertSame(PHP_INT_MAX, $parsedTaxonomy['tid']);
}
Expand Down
12 changes: 6 additions & 6 deletions test/Entity/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ class UserTest extends TestCase {

public function testFieldSingleValue() {
$user = new User();
$this->assertTrue($user->isSingleValued('uid'));
$this->assertTrue($user->isSingleValued('status'));
$this->assertTrue($user->isSingleValued('name'));
$this->assertFalse($user->isSingleValued('email'));
$this->assertTrue($user->isSingleValuedField('uid'));
$this->assertTrue($user->isSingleValuedField('status'));
$this->assertTrue($user->isSingleValuedField('name'));
$this->assertFalse($user->isSingleValuedField('email'));
}

public function testUserMockObject() {
$mockedUserInstance = new Entity('user', 'uid');
$sea = new EntityConvert();
$parsedUser = $sea->toArray($mockedUserInstance);
$ec = new EntityConvert();
$parsedUser = $ec->toArray($mockedUserInstance);
$this->assertArrayHasKey('uid', $parsedUser);
$this->assertSame(PHP_INT_MAX, $parsedUser['uid']);
}
Expand Down