Skip to content

Commit

Permalink
Improved set up for PhpUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Wolf committed Jun 6, 2018
1 parent 50d145c commit b166226
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 113 deletions.
3 changes: 2 additions & 1 deletion .coveralls.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
src_dir: src
service_name: travis-ci
coverage_clover: build/clover.xml
json_path: build/coveralls-upload.json
35 changes: 25 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
language: php

php:
- 7.1
- 7.2
env:
global:
- COMPOSER_ARGS="--no-interaction"
- COVERAGE_DEPS="php-coveralls/php-coveralls"

before_script:
- composer self-update
- composer install --dev --prefer-source --no-interaction
matrix:
include:
- php: 7.1
env:
- CS_CHECK=true
- MD_CHECK=true
- TEST_COVERAGE=true
- php: 7.2

before_install:
# - if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- cp phpunit.xml.dist phpunit.xml

install:
- travis_retry composer install $COMPOSER_ARGS --ignore-platform-reqs
- if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi
- stty cols 120 && composer show

script:
- php vendor/bin/phpunit -c travis.phpunit.xml
- php vendor/bin/phpmd src xml build/config/phpmd.xml --reportfile build/logs/pmd.xml
- php vendor/bin/phpcs --report=checkstyle --report-file=build/logs/checkstyle.xml --standard=build/config/phpcs.xml -v ./src/ ./tests/
- if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi
- if [[ $MD_CHECK == 'true' ]]; then composer md-check ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage-clover ; else composer test ; fi

after_script:
- php vendor/bin/coveralls
- if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry php vendor/bin/php-coveralls -v ; fi
3 changes: 0 additions & 3 deletions build/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
*
!config
!config/*
!logs
!.gitignore
31 changes: 0 additions & 31 deletions build/config/phpcs.xml

This file was deleted.

2 changes: 0 additions & 2 deletions build/logs/.gitignore

This file was deleted.

19 changes: 16 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
"require-dev": {
"ramsey/uuid": "^3.5",
"phpunit/phpunit": "^7.0",
"squizlabs/php_codesniffer" : "^2.2",
"phpmd/phpmd": "^2.1",
"php-coveralls/php-coveralls": "^2.0"
"squizlabs/php_codesniffer" : "^3.2",
"phpmd/phpmd": "^2.1"
},
"suggest": {
"ramsey/uuid": "For usage of the UUID handler of the JMS Serializer"
Expand All @@ -40,5 +39,19 @@
"psr-4": {
"DetailTest\\Normalization\\": "tests/"
}
},
"scripts": {
"check": [
"@cs-check",
"@md-check",
"@test"
],
"cs-check": "phpcs --standard=phpcs.xml -v",
"cs-check-report": "phpcs --standard=phpcs.xml --report=checkstyle --report-file=build/checkstyle.xml",
"md-check": "phpmd src xml phpmd.xml",
"md-check-report": "phpmd src xml phpmd.xml --reportfile build/pmd.xml",
"test": "phpunit",
"test-coverage-html": "phpunit --coverage-html build/coverage",
"test-coverage-clover": "phpunit --coverage-clover build/clover.xml"
}
}
17 changes: 17 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<ruleset name="DETAIL NET PHPCS rule set">
<description>The coding standard for a DETAIL NET PHP application</description>

<!-- Include the whole PSR-2 standard -->
<rule ref="PSR2"/>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="140"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>

<!-- Paths to check -->
<file>src</file>
<file>tests</file>
</ruleset>
File renamed without changes.
17 changes: 2 additions & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
<phpunit
bootstrap="./tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
verbose="true"
stopOnFailure="false"
processIsolation="false"
backupGlobals="false"
>
<phpunit bootstrap="./vendor/autoload.php" colors="true">
<testsuite name="Detail\Normalization Test Suite">
<directory>./tests</directory>
</testsuite>

<filter>
<whitelist>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
<log type="coverage-html" target="./build/coverage" lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="./build/logs/clover.xml"/>
<log type="junit" target="./build/logs/junit.xml"/>
</logging>
</phpunit>
1 change: 0 additions & 1 deletion tests/.gitignore

This file was deleted.

42 changes: 42 additions & 0 deletions tests/Normalizer/NormalizerAwareTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace DetailTest\Normalization\Normalizer;

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

use Detail\Normalization\Normalizer\NormalizerAwareTrait;
use Detail\Normalization\Normalizer\NormalizerInterface;

class NormalizerAwareTraitTest extends TestCase
{
/**
* @var MockObject
*/
private $normalizer;

protected function setUp()
{
$this->normalizer = $this->getMockBuilder(NormalizerInterface::CLASS)->getMock();
}

public function testSetsNormalizer(): void
{
/** @var NormalizerInterface $normalizer */
$normalizer = $this->getNormalizer();

/** @var NormalizerAwareTrait $object */
$object = $this->getMockBuilder(NormalizerAwareTrait::CLASS)->getMockForTrait();

$this->assertNull($object->getNormalizer());

$object->setNormalizer($normalizer);

$this->assertEquals($normalizer, $object->getNormalizer());
}

private function getNormalizer(): MockObject
{
return $this->normalizer;
}
}
18 changes: 0 additions & 18 deletions tests/bootstrap.php

This file was deleted.

3 changes: 0 additions & 3 deletions tests/configuration.php.dist

This file was deleted.

26 changes: 0 additions & 26 deletions travis.phpunit.xml

This file was deleted.

0 comments on commit b166226

Please sign in to comment.