Skip to content

Commit

Permalink
Added tests and analysis config
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Zamponi committed Nov 22, 2020
1 parent 59dc89a commit a2f45cc
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage_clover: clover.xml
json_path: coveralls-upload.json
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.coveralls.yml export-ignore
/.gitattributes export-ignore
/.github/ export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpcs.xml export-ignore
/phpunit.xml.dist export-ignore
/test/ export-ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Composer files
composer.phar
composer.lock
phpunit.xml
vendor/
.idea/
60 changes: 60 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
language: php

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

env:
global:
- COMPOSER_PROCESS_TIMEOUT=600
- COMPOSER_ARGS="--no-interaction"
- COVERAGE_DEPS="php-coveralls/php-coveralls"
- LOWEST_DEPS_REMOVE=""
- LATEST_DEPS_REQUIRE=""

matrix:
fast_finish: true
include:
- php: 7.3
env:
- DEPS=lowest
- php: 7.3
env:
- DEPS=latest
- CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.4
env:
- DEPS=lowest
- php: 7.4
env:
- DEPS=latest
- php: nightly
env:
- DEPS=lowest
- COMPOSER_ARGS="--no-interaction --ignore-platform-reqs"
- php: nightly
env:
- DEPS=latest
- COMPOSER_ARGS="--no-interaction --ignore-platform-reqs"

before_install:
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- if [[ $DEPS == 'lowest' ]]; then travis_retry composer remove $COMPOSER_ARGS --no-update --dev $LOWEST_DEPS_REMOVE ; fi
- if [[ $DEPS == 'latest' ]]; then travis_retry composer require $COMPOSER_ARGS --no-update --dev $LATEST_DEPS_REQUIRE ; fi

install:
- if [[ $DEPS == 'lowest' ]]; then travis_retry composer update $COMPOSER_ARGS --prefer-lowest ; fi
- if [[ $DEPS == 'latest' ]]; then travis_retry composer update $COMPOSER_ARGS ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi
- stty cols 120 && composer show

script:
- if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi
- if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi

after_script:
- if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry php vendor/bin/php-coveralls -v ; fi

notifications:
email: false
21 changes: 21 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,30 @@
"lm-commons/lmc-user": "~3.3",
"doctrine/doctrine-orm-module": "~3.0"
},
"require-dev": {
"laminas/laminas-coding-standard": "~1.0.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpspec/prophecy": "^1.12",
"phpunit/phpunit": "^9.3"
},
"autoload": {
"psr-4": {
"LmcUserDoctrineORM\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"LmcUserDoctrineORMTest\\": "test/"
}
},
"scripts": {
"check": [
"@cs-check",
"@test"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml"
}
}
7 changes: 7 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<ruleset name="Laminas coding standard">
<rule ref="./vendor/laminas/laminas-coding-standard/ruleset.xml"/>
<!-- Paths to check -->
<file>src</file>
<file>test</file>
</ruleset>
25 changes: 25 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="./vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="LmcUserDoctrineORM Test Suite">
<directory>./test/</directory>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>disable</group>
</exclude>
</groups>
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<php>
<ini name="date.timezone" value="UTC"/>
<ini name="error_reporting" value="E_ALL"/>
<ini name="max_execution_time" value="360"/>
</php>
</phpunit>
10 changes: 5 additions & 5 deletions src/Mapper/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function findById($id)
* @param null $tableName
* @param HydratorInterface|null $hydrator
*
* @return ResultInterface
* @return ResultInterface|UserInterface
*/
public function insert(UserInterface $entity, $tableName = null, HydratorInterface $hydrator = null)
{
Expand All @@ -88,19 +88,19 @@ public function insert(UserInterface $entity, $tableName = null, HydratorInterfa
* @param null $tableName
* @param HydratorInterface|null $hydrator
*
* @return ResultInterface
* @return ResultInterface|UserInterface
*/
public function update(UserInterface $entity, $where = null, $tableName = null, HydratorInterface $hydrator = null)
{
return $this->persist($entity);
}

/**
* @param $entity
* @param UserInterface $entity
*
* @return mixed
* @return UserInterface
*/
protected function persist(UserInterface $entity)
protected function persist(UserInterface $entity): UserInterface
{
$this->em->persist($entity);
$this->em->flush();
Expand Down
26 changes: 26 additions & 0 deletions test/Options/ModuleOptionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace LmcUserDoctrineORMTest\Options;

use LmcUserDoctrineORM\Options\ModuleOptions;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\TestCase;
use SebastianBergmann\RecursionContext\InvalidArgumentException;

/**
* Class ModuleOptionsTest
*/
class ModuleOptionsTest extends TestCase
{
/**
* @throws ExpectationFailedException
* @throws InvalidArgumentException
*/
public function testEnableDefaultEntitiesReturnsTrueByDefault(): void
{
$moduleOptions = new ModuleOptions();
self::assertTrue($moduleOptions->getEnableDefaultEntities());
}
}

0 comments on commit a2f45cc

Please sign in to comment.