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

CI, better tests, bugfixes and cleaning #103

Merged
merged 9 commits into from
Nov 27, 2020
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
9 changes: 9 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
versoin: 2
languages:
PHP: true
ratings:
paths:
- "**.php"
exclude_paths:
- tests
- vendor
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
/vendor/
/.idea/
/composer.lock
/.phpunit.result.cache
/.php_cs.cache
/phpunit
45 changes: 45 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
language: php
php:
- 7.2
- 7.3
- 7.4
env:
- ILLUMINATE_DATABASE=5.6
- ILLUMINATE_DATABASE=~5.0
- ILLUMINATE_DATABASE=~6.0
- ILLUMINATE_DATABASE=~7.0
- ILLUMINATE_DATABASE=~8.0
jobs:
include:
- php: 7.1
env: ILLUMINATE_DATABASE=5.6
- php: 7.1
env: ILLUMINATE_DATABASE=~5.0
exclude:
- php: 7.2
env: ILLUMINATE_DATABASE=~8.0
allow_failures:
- php: 7.3
env: ILLUMINATE_DATABASE=5.6
- php: 7.4
env: ILLUMINATE_DATABASE=5.6
git:
depth: 3
submodules: false
dist: xenial
os: linux
install:
- composer require "illuminate/database:$ILLUMINATE_DATABASE"
- composer update
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.0" ]] || [[ ${TRAVIS_PHP_VERSION:0:3} == "7.1" ]]; then wget -O vendor/bin/phpunit https://phar.phpunit.de/phpunit-6.phar; fi
- if [ ! -f "vendor/bin/phpunit" ]; then wget -O vendor/bin/phpunit https://phar.phpunit.de/phpunit-8.phar; fi
- chmod +x vendor/bin/phpunit
before_script:
- wget -O cc-test-reporter https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
- chmod +x cc-test-reporter
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter before-build; fi
script:
- ./vendor/bin/phpunit --version
- ./vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml
after_script:
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,19 @@ We use [SemVer](http://semver.org/) for versioning. For the versions available,

## Unit Tests

In order to run the test suite, install the development dependencies:
To run unit tests you have to obtain manually proper version of PHPUnit

```bash
$ composer install --dev
```

Then, run the following command:
* if you have PHP version 7.0 or 7.1 please get [PHPUnit 6](https://phar.phpunit.de/phpunit-6.phar)
* if you have PHP version 7.2 and higher please get [PHPUnit 8](https://phar.phpunit.de/phpunit-8.phar)

Example
```bash
$ vendor/bin/phpunit
wget -O phpunit https://phar.phpunit.de/phpunit-8.phar
chmod +x phpunit
./phpunit
```


## Authors

* [Claudin J. Daniel](https://github.com/topclaudy) - *Initial work*
Expand Down
22 changes: 6 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,19 @@
}
],
"require": {
"php": ">=5.6.4",
"illuminate/database": "^7.27|~8.0",
"illuminate/console": "~5.4|~6.0|~7.0|~8.0",
"illuminate/support": "~5.4|~6.0|~7.0|~8.0",
"illuminate/cache": "~5.4|~6.0|~7.0|~8.0"
"illuminate/database": ">=5.6 <9.0"
},
"require-dev": {
"phpunit/phpunit": "5.*",
"laravel/laravel": "~5.4|~6.0|~7.0|~8.0",
"fzaninotto/faker": "^1.8"
"ext-sqlite3": "*"
},
"autoload": {
"psr-4": {
"Awobaz\\Compoships\\": "src"
},
"files": [
]
}
},
"extra": {
"laravel": {
"providers": [
"Awobaz\\Compoships\\ComposhipsServiceProvider"
]
"autoload-dev": {
"psr-4": {
"Awobaz\\Compoships\\Tests\\": "tests"
}
},
"suggest": {
Expand Down
17 changes: 0 additions & 17 deletions phpunit.xml

This file was deleted.

29 changes: 29 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true">
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
26 changes: 0 additions & 26 deletions src/ComposhipsServiceProvider.php

This file was deleted.

12 changes: 4 additions & 8 deletions src/Database/Eloquent/Concerns/HasRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Awobaz\Compoships\Database\Eloquent\Concerns;

use Awobaz\Compoships\Compoships;
use Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo;
use Awobaz\Compoships\Database\Eloquent\Relations\HasMany;
use Awobaz\Compoships\Database\Eloquent\Relations\HasOne;
Expand Down Expand Up @@ -89,18 +90,13 @@ protected function newHasOne(Builder $query, Model $parent, $foreignKey, $localK
* Validate the related model for Compoships compatibility.
*
* @param $related
*
* @throws InvalidUsageException
*
* @return void
*/
private function validateRelatedModel($related)
{
$uses = class_uses_recursive($related);

if (!array_key_exists('Awobaz\Compoships\Compoships', $uses) && !is_subclass_of($related,
'Awobaz\Compoships\Database\Eloquent\Model')) {
throw new InvalidUsageException("The related model '${related}' must either extend 'Awobaz\Compoships\Database\Eloquent\Model' or use the 'Awobaz\Compoships\Compoships' trait");
$traitClass = Compoships::class;
if (!array_key_exists($traitClass, class_uses_recursive($related))) {
throw new InvalidUsageException("The related model '{$related}' must use the '{$traitClass}' trait");
}
}

Expand Down
11 changes: 0 additions & 11 deletions src/Database/Eloquent/Model.php

This file was deleted.

39 changes: 21 additions & 18 deletions src/Database/Eloquent/Relations/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ public function getResults()
*/
public function associate($model)
{
if (is_array($this->ownerKey)) {

$ownerKey = $model instanceof Model ? $model->getAttribute($this->ownerKey) : $model;
for ($i = 0; $i < count($this->foreignKey); $i++) {
$foreignKey = $this->foreignKey[$i];
$value = $ownerKey[$i];
$this->child->setAttribute($foreignKey, $value);
}

if ($model instanceof Model) {
$this->child->setRelation($this->relationName, $model);
} else {
$this->child->unsetRelation($this->relationName);
}

return $this->child;

} else {
if (!is_array($this->ownerKey)) {
return parent::associate($model);
}

$ownerKey = $model instanceof Model ? $model->getAttribute($this->ownerKey) : $model;
for ($i = 0; $i < count($this->foreignKey); $i++) {
$foreignKey = $this->foreignKey[$i];
$value = $ownerKey[$i];
$this->child->setAttribute($foreignKey, $value);
}
// BC break in 5.8 : https://github.com/illuminate/database/commit/87b9833019f48b88d98a6afc46f38ce37f08237d
$relationName = property_exists($this, 'relationName') ? $this->relationName : $this->relation;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe throw error if 'relation' does not exist too

if ($model instanceof Model) {
$this->child->setRelation($relationName, $model);
// proper unset // https://github.com/illuminate/database/commit/44411c7288fc7b7d4e5680cfcdaa46d348b5c981
} elseif ($this->child->isDirty($this->foreignKey)) {
$this->child->unsetRelation($relationName);
}

return $this->child;
}

/**
Expand Down Expand Up @@ -107,6 +107,9 @@ public function addEagerConstraints(array $models)
$keys[] = $this->related->getTable().'.'.$key;
}

// method \Awobaz\Compoships\Database\Eloquent\Relations\HasOneOrMany::whereInMethod
// 5.6 - does not exist
// 5.7 - added in 5.7.17 / https://github.com/illuminate/database/commit/9af300d1c50c9ec526823c1e6548daa3949bf9a9
$this->query->whereIn($keys, $this->getEagerModelKeys($models));
} else {
parent::addEagerConstraints($models);
Expand Down
5 changes: 4 additions & 1 deletion src/Database/Eloquent/Relations/HasOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ public function addConstraints()
* Get the name of the "where in" method for eager loading.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string|array $key
* @param string|array $key
*
* @return string
*
* 5.6 - no method \Awobaz\Compoships\Database\Eloquent\Relations\HasOneOrMany::whereInMethod
* added in this commit (5.7.17) https://github.com/illuminate/database/commit/9af300d1c50c9ec526823c1e6548daa3949bf9a9
*/
protected function whereInMethod(Model $model, $key)
{
Expand Down
Empty file removed tests/.gitkeep
Empty file.
Loading