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

add integration test #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.path = ${basedir}/composer.phar

#PHP Code Sniffer
phpcs.standard = PEAR
phpcs.symfony_standard = Symfony
11 changes: 9 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<istrue value="${env.TRAVIS}" />
</condition>

<target name="test" depends="vendor,lint,phpunit,phpcs" />
<target name="test" depends="vendor,lint,phpunit,phpcs,phpcs_symfony" />

<target name="prepare" depends="clean" description="Prepare for build">
<mkdir dir="${basedir}/build/coverage" />
Expand Down Expand Up @@ -46,8 +46,15 @@
<exec executable="./vendor/bin/phpcs" failonerror="true">
<arg value="--standard=${phpcs.standard}" />
<arg value="--extensions=php" />
<arg value="--ignore=vendor/*" />
<arg value="--ignore=vendor/*,test/*" />
<arg path="${basedir}" />
</exec>
</target>

<target name="phpcs_symfony" description="Test Symfony CS against example file from docs">
<exec executable="./vendor/bin/phpcs" failonerror="true">
<arg value="--standard=${phpcs.symfony_standard}" />
<arg path="${basedir}/test/FooBar.php" />
</exec>
</target>
</project>
110 changes: 110 additions & 0 deletions test/FooBar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Acme;

use Other\Qux;

/**
* Coding standards demonstration.
*/
class FooBar
{
const SOME_CONST = 42;

/**
* @var string
*/
private $fooBar;

private $qux;

/**
* @param string $dummy Some argument description
* @param Qux $qux This line is not in the example
*/
public function __construct($dummy, Qux $qux)
{
$this->fooBar = $this->transformText($dummy);
$this->qux = $qux;
}

/**
* @return string
*
* @deprecated
*/
public function someDeprecatedMethod()
{
trigger_deprecation('symfony/package-name', '5.1', 'The %s() method is deprecated, use Acme\Baz::someMethod() instead.', __METHOD__);

return Baz::someMethod();
}

/**
* Transforms the input given as first argument.
*
* @param bool|string $dummy Some argument description
* @param array $options An options collection to be used within the transformation
*
* @return string|null The transformed input
*
* @throws \RuntimeException When an invalid option is provided
*/
private function transformText($dummy, array $options = [])
{
$defaultOptions = [
'some_default' => 'values',
'another_default' => 'more values',
];

foreach ($options as $name => $value) {
if (!array_key_exists($name, $defaultOptions)) {
throw new \RuntimeException(sprintf('Unrecognized option "%s"', $name));
}
}

$mergedOptions = array_merge(
$defaultOptions,
$options
);

if (true === $dummy) {
return 'something';
}

if (is_string($dummy)) {
if ('values' === $mergedOptions['some_default']) {
return substr($dummy, 0, 5);
}

return ucwords($dummy);
}

return null;
}

/**
* Performs some basic operations for a given value.
*
* @param mixed $value Some value to operate against
* @param bool $theSwitch Some switch to control the method's flow
*/
private function performOperations($value = null, $theSwitch = false)
{
if (!$theSwitch) {
return;
}

$this->qux->doFoo($value);
$this->qux->doBar($value);
}
}