diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..a1f7699 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,20 @@ +imports: + - php + +tools: + # PHP Similarity Analyzer and Copy/paste Detector cannot be used at + # the same time right now. Make sure to either remove, or disable one. + php_sim: true + php_cpd: false + + php_changetracking: true + + php_cs_fixer: + config: { level: psr2 } + + php_pdepend: true + + php_mess_detector: true + + external_code_coverage: + timeout: 1800 diff --git a/.travis.yml b/.travis.yml index bd72ea6..84c3df5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,13 +4,27 @@ php: - 5.3 - 5.4 - 5.5 + - 5.6 - hhvm before_script: - composer self-update - - composer install - - git config --global user.email "scrutinizer-ci@github.com" - - git config --global user.name "Scrutinizer-CI" + - composer install --dev --prefer-source; + - wget https://scrutinizer-ci.com/ocular.phar + - sh -c "if [ '$TRAVIS_PHP_VERSION' != '5.3' ]; then echo 'starting PHP server on port 8080'; php -S localhost:8080 -d max_execution_time=10 -t tests/ tests/_files/_route-script.php & fi" +script: + - phpunit --configuration ./tests/phpunit.xml + - ./vendor/bin/phpcs -n --standard=PSR2 ./src/ ./tests/ -script: phpunit +after_script: + - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml + +notifications: + email: false + +matrix: + fast_finish: true + allow_failures: + - php: 5.6 + - php: hhvm diff --git a/composer.json b/composer.json index 4f0898b..8d80719 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ "jms/serializer": "~0.13" }, "require-dev": { + "squizlabs/php_codesniffer": "~1", "symfony/filesystem": "~2.0" } -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock deleted file mode 100644 index bbe4a16..0000000 --- a/composer.lock +++ /dev/null @@ -1,693 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" - ], - "hash": "dea03ec70dc6fe130c104dc4cb2df4c0", - "packages": [ - { - "name": "doctrine/annotations", - "version": "v1.1.2", - "source": { - "type": "git", - "url": "https://github.com/doctrine/annotations.git", - "reference": "40db0c96985aab2822edbc4848b3bd2429e02670" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/40db0c96985aab2822edbc4848b3bd2429e02670", - "reference": "40db0c96985aab2822edbc4848b3bd2429e02670", - "shasum": "" - }, - "require": { - "doctrine/lexer": "1.*", - "php": ">=5.3.2" - }, - "require-dev": { - "doctrine/cache": "1.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-0": { - "Doctrine\\Common\\Annotations\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com", - "homepage": "http://www.jwage.com/" - }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com", - "homepage": "http://www.instaclick.com" - }, - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com", - "homepage": "http://jmsyst.com", - "role": "Developer of wrapped JMSSerializerBundle" - } - ], - "description": "Docblock Annotations Parser", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "annotations", - "docblock", - "parser" - ], - "time": "2013-06-16 21:33:03" - }, - { - "name": "doctrine/lexer", - "version": "v1.0", - "source": { - "type": "git", - "url": "https://github.com/doctrine/lexer.git", - "reference": "2f708a85bb3aab5d99dab8be435abd73e0b18acb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/lexer/zipball/2f708a85bb3aab5d99dab8be435abd73e0b18acb", - "reference": "2f708a85bb3aab5d99dab8be435abd73e0b18acb", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "type": "library", - "autoload": { - "psr-0": { - "Doctrine\\Common\\Lexer\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com", - "homepage": "http://www.instaclick.com" - }, - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com", - "homepage": "http://jmsyst.com", - "role": "Developer of wrapped JMSSerializerBundle" - } - ], - "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "lexer", - "parser" - ], - "time": "2013-01-12 18:59:04" - }, - { - "name": "guzzle/guzzle", - "version": "v3.7.3", - "source": { - "type": "git", - "url": "https://github.com/guzzle/guzzle.git", - "reference": "0f16aad385528b5cf790392cb4a4d16cf600e944" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/0f16aad385528b5cf790392cb4a4d16cf600e944", - "reference": "0f16aad385528b5cf790392cb4a4d16cf600e944", - "shasum": "" - }, - "require": { - "ext-curl": "*", - "php": ">=5.3.2", - "symfony/event-dispatcher": ">=2.1" - }, - "replace": { - "guzzle/batch": "self.version", - "guzzle/cache": "self.version", - "guzzle/common": "self.version", - "guzzle/http": "self.version", - "guzzle/inflection": "self.version", - "guzzle/iterator": "self.version", - "guzzle/log": "self.version", - "guzzle/parser": "self.version", - "guzzle/plugin": "self.version", - "guzzle/plugin-async": "self.version", - "guzzle/plugin-backoff": "self.version", - "guzzle/plugin-cache": "self.version", - "guzzle/plugin-cookie": "self.version", - "guzzle/plugin-curlauth": "self.version", - "guzzle/plugin-error-response": "self.version", - "guzzle/plugin-history": "self.version", - "guzzle/plugin-log": "self.version", - "guzzle/plugin-md5": "self.version", - "guzzle/plugin-mock": "self.version", - "guzzle/plugin-oauth": "self.version", - "guzzle/service": "self.version", - "guzzle/stream": "self.version" - }, - "require-dev": { - "doctrine/cache": "*", - "monolog/monolog": "1.*", - "phpunit/phpunit": "3.7.*", - "psr/log": "1.0.*", - "symfony/class-loader": "*", - "zendframework/zend-cache": "2.0.*", - "zendframework/zend-log": "2.0.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.7-dev" - } - }, - "autoload": { - "psr-0": { - "Guzzle\\Tests": "tests/", - "Guzzle": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Guzzle Community", - "homepage": "https://github.com/guzzle/guzzle/contributors" - } - ], - "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "client", - "curl", - "framework", - "http", - "http client", - "rest", - "web service" - ], - "time": "2013-09-08 21:09:18" - }, - { - "name": "jms/metadata", - "version": "1.4.2", - "source": { - "type": "git", - "url": "https://github.com/schmittjoh/metadata.git", - "reference": "246d7096801ce29b5aea30a1abf0277ccfb9f055" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/metadata/zipball/246d7096801ce29b5aea30a1abf0277ccfb9f055", - "reference": "246d7096801ce29b5aea30a1abf0277ccfb9f055", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "require-dev": { - "doctrine/cache": "~1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4.x-dev" - } - }, - "autoload": { - "psr-0": { - "Metadata\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache" - ], - "authors": [ - { - "name": "Johannes M. Schmitt", - "email": "schmittjoh@gmail.com", - "homepage": "http://jmsyst.com", - "role": "Developer of wrapped JMSSerializerBundle" - } - ], - "description": "Class/method/property metadata management in PHP", - "keywords": [ - "annotations", - "metadata", - "xml", - "yaml" - ], - "time": "2013-09-13 09:05:44" - }, - { - "name": "jms/parser-lib", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/schmittjoh/parser-lib.git", - "reference": "c509473bc1b4866415627af0e1c6cc8ac97fa51d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/parser-lib/zipball/c509473bc1b4866415627af0e1c6cc8ac97fa51d", - "reference": "c509473bc1b4866415627af0e1c6cc8ac97fa51d", - "shasum": "" - }, - "require": { - "phpoption/phpoption": ">=0.9,<2.0-dev" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-0": { - "JMS\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache2" - ], - "description": "A library for easily creating recursive-descent parsers.", - "time": "2012-11-18 18:08:43" - }, - { - "name": "jms/serializer", - "version": "0.13.0", - "source": { - "type": "git", - "url": "https://github.com/schmittjoh/serializer.git", - "reference": "9e0fcd00a374e9ad484687628c6c25ab1083ea5a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/serializer/zipball/9e0fcd00a374e9ad484687628c6c25ab1083ea5a", - "reference": "9e0fcd00a374e9ad484687628c6c25ab1083ea5a", - "shasum": "" - }, - "require": { - "doctrine/annotations": "1.*", - "jms/metadata": "~1.1", - "jms/parser-lib": "1.*", - "php": ">=5.3.2", - "phpcollection/phpcollection": ">=0.1,<0.3-dev" - }, - "require-dev": { - "doctrine/orm": ">=2.1,<2.4-dev", - "symfony/filesystem": "2.*", - "symfony/form": ">=2.1,<2.2-dev", - "symfony/translation": ">=2.0,<2.2-dev", - "symfony/validator": ">=2.0,<2.2-dev", - "symfony/yaml": "2.*", - "twig/twig": ">=1.8,<2.0-dev" - }, - "suggest": { - "symfony/yaml": "Required if you'd like to serialize data to YAML format." - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.13-dev" - } - }, - "autoload": { - "psr-0": { - "JMS\\Serializer": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache2" - ], - "authors": [ - { - "name": "Johannes M. Schmitt", - "email": "schmittjoh@gmail.com", - "homepage": "https://github.com/schmittjoh", - "role": "Developer of wrapped JMSSerializerBundle" - } - ], - "description": "Library for (de-)serializing data of any complexity; supports XML, JSON, and YAML.", - "homepage": "http://jmsyst.com/libs/serializer", - "keywords": [ - "deserialization", - "jaxb", - "json", - "serialization", - "xml" - ], - "time": "2013-07-29 13:39:49" - }, - { - "name": "phpcollection/phpcollection", - "version": "0.2.0", - "source": { - "type": "git", - "url": "https://github.com/schmittjoh/php-collection.git", - "reference": "acb02a921bb364f360ce786b13455345063c4a07" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/php-collection/zipball/acb02a921bb364f360ce786b13455345063c4a07", - "reference": "acb02a921bb364f360ce786b13455345063c4a07", - "shasum": "" - }, - "require": { - "phpoption/phpoption": "1.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.2-dev" - } - }, - "autoload": { - "psr-0": { - "PhpCollection": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache2" - ], - "authors": [ - { - "name": "Johannes M. Schmitt", - "email": "schmittjoh@gmail.com", - "homepage": "http://jmsyst.com", - "role": "Developer of wrapped JMSSerializerBundle" - } - ], - "description": "General-Purpose Collection Library for PHP", - "keywords": [ - "collection", - "list", - "map", - "sequence", - "set" - ], - "time": "2013-01-23 15:16:14" - }, - { - "name": "phpoption/phpoption", - "version": "1.3.0", - "source": { - "type": "git", - "url": "https://github.com/schmittjoh/php-option.git", - "reference": "1c7e8016289d17d83ced49c56d0f266fd0568941" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/1c7e8016289d17d83ced49c56d0f266fd0568941", - "reference": "1c7e8016289d17d83ced49c56d0f266fd0568941", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3-dev" - } - }, - "autoload": { - "psr-0": { - "PhpOption\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache2" - ], - "authors": [ - { - "name": "Johannes M. Schmitt", - "email": "schmittjoh@gmail.com", - "homepage": "http://jmsyst.com", - "role": "Developer of wrapped JMSSerializerBundle" - } - ], - "description": "Option Type for PHP", - "keywords": [ - "language", - "option", - "php", - "type" - ], - "time": "2013-05-19 11:09:35" - }, - { - "name": "symfony/console", - "version": "v2.3.4", - "target-dir": "Symfony/Component/Console", - "source": { - "type": "git", - "url": "https://github.com/symfony/Console.git", - "reference": "db78f8ff7fc9e28d25ff9a0bf6ddf9f0e35fbbe3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/db78f8ff7fc9e28d25ff9a0bf6ddf9f0e35fbbe3", - "reference": "db78f8ff7fc9e28d25ff9a0bf6ddf9f0e35fbbe3", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "symfony/event-dispatcher": "~2.1" - }, - "suggest": { - "symfony/event-dispatcher": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.3-dev" - } - }, - "autoload": { - "psr-0": { - "Symfony\\Component\\Console\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - } - ], - "description": "Symfony Console Component", - "homepage": "http://symfony.com", - "time": "2013-08-17 16:34:49" - }, - { - "name": "symfony/event-dispatcher", - "version": "v2.3.4", - "target-dir": "Symfony/Component/EventDispatcher", - "source": { - "type": "git", - "url": "https://github.com/symfony/EventDispatcher.git", - "reference": "41c9826457c65fa3cf746f214985b7ca9cba42f8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/41c9826457c65fa3cf746f214985b7ca9cba42f8", - "reference": "41c9826457c65fa3cf746f214985b7ca9cba42f8", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "symfony/dependency-injection": "~2.0" - }, - "suggest": { - "symfony/dependency-injection": "", - "symfony/http-kernel": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.3-dev" - } - }, - "autoload": { - "psr-0": { - "Symfony\\Component\\EventDispatcher\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - } - ], - "description": "Symfony EventDispatcher Component", - "homepage": "http://symfony.com", - "time": "2013-07-21 12:12:18" - }, - { - "name": "symfony/process", - "version": "v2.3.4", - "target-dir": "Symfony/Component/Process", - "source": { - "type": "git", - "url": "https://github.com/symfony/Process.git", - "reference": "1e91553e1cedd0b8fb1da6ea4f89b02e21713d5b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Process/zipball/1e91553e1cedd0b8fb1da6ea4f89b02e21713d5b", - "reference": "1e91553e1cedd0b8fb1da6ea4f89b02e21713d5b", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.3-dev" - } - }, - "autoload": { - "psr-0": { - "Symfony\\Component\\Process\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - } - ], - "description": "Symfony Process Component", - "homepage": "http://symfony.com", - "time": "2013-08-22 06:42:25" - } - ], - "packages-dev": [ - { - "name": "symfony/filesystem", - "version": "v2.3.4", - "target-dir": "Symfony/Component/Filesystem", - "source": { - "type": "git", - "url": "https://github.com/symfony/Filesystem.git", - "reference": "87acbbef6d35ba649f96f09cc572c45119b360c3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Filesystem/zipball/87acbbef6d35ba649f96f09cc572c45119b360c3", - "reference": "87acbbef6d35ba649f96f09cc572c45119b360c3", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.3-dev" - } - }, - "autoload": { - "psr-0": { - "Symfony\\Component\\Filesystem\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - } - ], - "description": "Symfony Filesystem Component", - "homepage": "http://symfony.com", - "time": "2013-07-21 12:12:18" - } - ], - "aliases": [ - - ], - "minimum-stability": "stable", - "stability-flags": [ - - ], - "platform": [ - - ], - "platform-dev": [ - - ] -} diff --git a/src/Scrutinizer/Ocular/Command/CodeCoverage/UploadCommand.php b/src/Scrutinizer/Ocular/Command/CodeCoverage/UploadCommand.php index 286d04d..ba057fd 100644 --- a/src/Scrutinizer/Ocular/Command/CodeCoverage/UploadCommand.php +++ b/src/Scrutinizer/Ocular/Command/CodeCoverage/UploadCommand.php @@ -44,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $client->addSubscriber(BackoffPlugin::getExponentialBackoff()); $postData = $this->generatePostData($input); - if ( ! isset($postData['coverage'])) { + if (!isset($postData['coverage'])) { $output->write(sprintf('Notifying that no code coverage data is available for repository "%s" and revision "%s"... ', $repositoryName, $postData['revision'])); } else { $output->write(sprintf('Uploading code coverage for repository "%s" and revision "%s"... ', $repositoryName, $postData['revision'])); @@ -101,11 +101,14 @@ private function getCoverageData($file) private function getBasePath() { $dir = getcwd(); - while ( ! empty($dir)) { + $lastestDir = null; + + while (!empty($dir) && $dir !== $lastestDir) { if (is_dir($dir.'/.git')) { return $dir; } + $lastestDir = $dir; $dir = dirname($dir); } @@ -123,10 +126,10 @@ private function parseFormat($format) private function parseRepositoryName($name) { - if ( ! empty($name)) { + if (!empty($name)) { return $name; } - + $repoInspector = new RepositoryIntrospector(getcwd()); return $repoInspector->getQualifiedName(); @@ -134,7 +137,7 @@ private function parseRepositoryName($name) private function parseRevision($inputRevision) { - if ( ! empty($inputRevision)) { + if (!empty($inputRevision)) { return $inputRevision; } @@ -145,7 +148,7 @@ private function parseRevision($inputRevision) private function parseParents(array $parents) { - if ( ! empty($parents)) { + if (!empty($parents)) { return $parents; } @@ -153,4 +156,4 @@ private function parseParents(array $parents) return $repoInspector->getCurrentParents(); } -} \ No newline at end of file +} diff --git a/src/Scrutinizer/Ocular/Command/SelfUpdateCommand.php b/src/Scrutinizer/Ocular/Command/SelfUpdateCommand.php index 1d40c9e..2f9b557 100644 --- a/src/Scrutinizer/Ocular/Command/SelfUpdateCommand.php +++ b/src/Scrutinizer/Ocular/Command/SelfUpdateCommand.php @@ -48,4 +48,4 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('You are already using the latest version.'); } } -} \ No newline at end of file +} diff --git a/src/Scrutinizer/Ocular/Configuration.php b/src/Scrutinizer/Ocular/Configuration.php index 059e901..ba09f89 100644 --- a/src/Scrutinizer/Ocular/Configuration.php +++ b/src/Scrutinizer/Ocular/Configuration.php @@ -3,9 +3,15 @@ namespace Scrutinizer\Ocular; use PhpOption\Option; +use JMS\Serializer\Annotation\Type; class Configuration { + /** + * + * @var string + * @Type("string") + */ private $accessToken; public function __construct($accessToken = null) @@ -17,4 +23,4 @@ public function getAccessToken() { return Option::fromValue($this->accessToken); } -} \ No newline at end of file +} diff --git a/src/Scrutinizer/Ocular/Ocular.php b/src/Scrutinizer/Ocular/Ocular.php index d9c45fc..490c9ab 100644 --- a/src/Scrutinizer/Ocular/Ocular.php +++ b/src/Scrutinizer/Ocular/Ocular.php @@ -37,7 +37,7 @@ private function registerCommands() private function loadConfiguration() { $homeDir = getenv('HOME'); - if ( ! is_file($homeDir.'/.ocular/config.json')) { + if (!is_file($homeDir.'/.ocular/config.json')) { return new Configuration(); } @@ -47,4 +47,4 @@ private function loadConfiguration() 'json' ); } -} \ No newline at end of file +} diff --git a/src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php b/src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php index b96ac8a..602d54e 100644 --- a/src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php +++ b/src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php @@ -75,4 +75,4 @@ private function getRepositoryType($host) throw new \LogicException(sprintf('Unknown host "%s".', $host)); } } -} \ No newline at end of file +} diff --git a/tests/Scrutinizer/Tests/Ocular/AbstractTestCaseClass.php b/tests/Scrutinizer/Tests/Ocular/AbstractTestCaseClass.php new file mode 100644 index 0000000..a46fc0c --- /dev/null +++ b/tests/Scrutinizer/Tests/Ocular/AbstractTestCaseClass.php @@ -0,0 +1,105 @@ +currentTmpDir; + + $proc = new Process($cmd, $dir ?: $this->currentTmpDir); + if ($proc->run() !== 0) { + throw new ProcessFailedException($proc); + } + + return trim($proc->getOutput()); + } + + protected function getTempDir($setDefault = true, $mkdir = false) + { + $tmpDir = tempnam(sys_get_temp_dir(), 'ocular-intro'); + unlink($tmpDir); + + if ($setDefault) { + $this->currentTmpDir = $tmpDir; + } + if ($mkdir) { + mkdir($tmpDir, $mkdir, true); + } + + return $this->tmpDirs[] = $tmpDir; + } + + protected function cloneRepository($url, $dir = null) + { + $this->installRepository($dir); + $this->exec('git remote add origin ' . $url); + } + + protected function installRepository($dir = null) + { + $this->exec('git init', $dir); + $this->exec('git config user.email "scrutinizer-ci@github.com"', $dir); + $this->exec('git config user.name "Scrutinizer-CI"', $dir); + } + + protected function helperReflectionMethode($object, $methodeName) + { + $reflection = new \ReflectionMethod($object, $methodeName); + $reflection->setAccessible(true); + + return $reflection; + } + + /** + * + * @param string|object $object + * @param string $propertyName + * @return \ReflectionProperty + */ + protected function helperReflectionProperty($object, $propertyName) + { + $objectReflection = new \ReflectionObject($object); + $reflection = $objectReflection; + + while ($reflection = $reflection->getParentClass()) { + if ($reflection->hasProperty($propertyName)) { + break; + } + } + + if (!$reflection->hasProperty($propertyName)) { + throw new \InvalidArgumentException(sprintf( + 'property (%s) is not exists in the object from class "%s"', + $propertyName, + get_class($object) + )); + } + + $reflectionProperty = $reflection->getProperty($propertyName); + $reflectionProperty->setAccessible(true); + + return $reflectionProperty; + } + + /** + * + * @param string|object $object + * @param string $propertyName + * @return \ReflectionProperty + */ + protected function skipIfPhpVersionDonotSupportBuildInServer() + { + if (version_compare(phpversion(), "5.4", '>=')) { + return; + } + $this->markTestSkipped("php lower then 5.4 don't support buildin Server"); + } +} diff --git a/tests/Scrutinizer/Tests/Ocular/Command/CodeCoverage/UpdateCommandTest.php b/tests/Scrutinizer/Tests/Ocular/Command/CodeCoverage/UpdateCommandTest.php new file mode 100644 index 0000000..ac93e67 --- /dev/null +++ b/tests/Scrutinizer/Tests/Ocular/Command/CodeCoverage/UpdateCommandTest.php @@ -0,0 +1,358 @@ +SUT = new UploadCommand(); + + $this->input = $this->getMock('\Symfony\Component\Console\Input\InputInterface'); + $this->output = $this->getMock('\Symfony\Component\Console\Output\OutputInterface'); + } + + /** + * @dataProvider providerTestExecute + */ + public function testExecute($withCoverageFile, $statusCode = '200') + { + $this->skipIfPhpVersionDonotSupportBuildInServer(); + + $repositoryName = "scrutinizer-ocular"; + $accessToken = md5("success"); + $revision = md5('rev1'); + + $this->inputGetOptionMap[] = array('repository', &$repositoryName); + $this->inputGetOptionMap[] = array('api-url', "http://localhost:8080/"); + $this->inputGetOptionMap[] = array('access-token', &$accessToken); + + $this->helperMockGeneratePostData($withCoverageFile, $revision); + + $this->input->expects($this->any()) + ->method('getOption') + ->will($this->returnValueMap($this->inputGetOptionMap)); + + if ($statusCode === '200') { + $this->output->expects($this->once()) + ->method('writeln') + ->with('Done'); + } else { + $this->output->expects($this->at(1)) + ->method('writeln') + ->with('Failed'); + + if ($statusCode === '403') { + $accessToken = md5('no access'); + $this->output->expects($this->at(2)) + ->method('writeln') + ->with('no access with the token "' . var_export(array($accessToken, $accessToken), true) .'"'); + } else { + $repositoryName = 'with-internal-server-error'; + } + } + + if (!$withCoverageFile) { + $message = sprintf( + 'Notifying that no code coverage data is available for repository "%s" and revision "%s"... ', + $repositoryName, + $revision + ); + } else { + $message = sprintf( + 'Uploading code coverage for repository "%s" and revision "%s"... ', + $repositoryName, + $revision + ); + } + + $this->output->expects($this->once()) + ->method('write') + ->with($message); + + $reflection = $this->helperReflectionMethode($this->SUT, 'execute'); + + if ($statusCode === '500') { + $this->setExpectedException('\Guzzle\Http\Exception\BadResponseException'); + } + + $result = $reflection->invoke($this->SUT, $this->input, $this->output); + + if ($statusCode === '200') { + $this->assertEquals(0, $result); + } elseif (substr($statusCode, 0, 1) === '4') { + $this->assertEquals(1, $result); + } + } + + public function testGeneratePostData() + { + $this->helperMockGeneratePostData(true); + + $this->input->expects($this->any()) + ->method('getOption') + ->will($this->returnValueMap($this->inputGetOptionMap)); + + + $reflection = $this->helperReflectionMethode($this->SUT, 'generatePostData'); + $result = $reflection->invoke($this->SUT, $this->input); + + $this->assertInternalType('array', $result); + $this->assertArrayHasKey('revision', $result); + $this->assertArrayHasKey('parents', $result); + $this->assertArrayHasKey('coverage', $result); + } + + public function testGetCoverageData() + { + $this->getTempDir(true, 0777); + $this->installRepository(); + $subdir[] = md5(rand(0, 1000)); + $subdir[] = md5(rand(0, 1000)); + + $subdir = $this->currentTmpDir . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $subdir); + mkdir($subdir, 0777, true); + chdir($subdir); + + + $buildDir = $this->currentTmpDir . DIRECTORY_SEPARATOR . 'build'; + mkdir($buildDir, 0777, true); + + $coverageFile = $buildDir . DIRECTORY_SEPARATOR . 'coverage.xml'; + file_put_contents( + $coverageFile, + sprintf( + '' . + '', + $this->currentTmpDir + ) + ); + + $reflection = $this->helperReflectionMethode($this->SUT, 'getCoverageData'); + $result = $reflection->invoke($this->SUT, $coverageFile); + + $this->assertInternalType('string', $result); + $this->assertGreaterThan(2, strlen($result)); + + + $this->assertRegExp('#{scrutinizer_project_base_path}/test1#', $result); + $this->assertRegExp('#{scrutinizer_project_base_path}/test2#', $result); + $this->assertRegExp('#{scrutinizer_project_base_path}/test3#', $result); + $this->assertRegExp('#{scrutinizer_project_base_path}/test4#', $result); + } + + public function testGetBasePath() + { + $this->getTempDir(true, 0777); + $this->installRepository(); + $subdir[] = md5(rand(0, 1000)); + $subdir[] = md5(rand(0, 1000)); + + $subdir = $this->currentTmpDir . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $subdir); + + mkdir($subdir, 0777, true); + chdir($subdir); + + $reflection = $this->helperReflectionMethode($this->SUT, 'getBasePath'); + + $result = $reflection->invoke($this->SUT); + + $this->assertInternalType('string', $result); + $this->assertGreaterThan(2, strlen($result)); + $this->assertTrue(is_dir($subdir)); + } + + /** + * @expectedException \LogicException + */ + public function testGetBasePathFail() + { + $this->getTempDir(true, 0777); + chdir($this->currentTmpDir); + + $reflection = $this->helperReflectionMethode($this->SUT, 'getBasePath'); + $result = $reflection->invoke($this->SUT); + } + + /** + * + * @dataProvider providerTestParseMethodWithNotEmpty + */ + public function testParseMethodWithNotEmpty($method, $input, $expectedValue = null) + { + if ($expectedValue instanceof \Exception) { + $this->setExpectedException(get_class($expectedValue), $expectedValue->getMessage()); + } elseif (empty($input)) { + $expectedValue = $this->helperMockRepositoryIntrospector($method); + } else { + $expectedValue = $input; + } + + $reflection = $this->helperReflectionMethode($this->SUT, $method); + $result = $reflection->invoke($this->SUT, $input); + + $this->assertEquals($expectedValue, $result); + } + + public function testConfigure() + { + $this->assertEquals('code-coverage:upload', $this->SUT->getName()); + $this->assertGreaterThan(2, strlen($this->SUT->getDescription())); + + $definition = $this->SUT->getDefinition(); + + $this->assertTrue($definition->hasArgument('coverage-file')); + $argument = $definition->getArgument('coverage-file'); + $this->assertInstanceOf('\Symfony\Component\Console\Input\InputArgument', $argument); + $this->assertEquals('coverage-file', $argument->getName()); + $this->assertTrue($argument->isRequired()); + + $optionsList = array( + // name, isRequired, isArray + array('api-url', true, false), + array('repository', true, false), + array('revision', true, false), + array('format', true, false), + array('parent', true, true) + ); + + foreach ($optionsList as $option) { + $this->assertTrue($definition->hasOption($option[0])); + $optionObj = $definition->getOption($option[0]); + $this->assertInstanceOf('\Symfony\Component\Console\Input\InputOption', $optionObj); + $this->assertEquals($option[0], $optionObj->getName()); + $this->assertSame($option[1], $optionObj->isValueRequired()); + $this->assertSame(!$option[1], $optionObj->isValueOptional()); + + $this->assertSame($option[2], $optionObj->isArray()); + } + } + + public function providerTestParseMethodWithNotEmpty() + { + return array( + array('parseParents', array('test')), + array('parseParents', array()), + + array('parseRevision', 'test'), + array('parseRevision', null), + + array('parseRepositoryName', 'test'), + array('parseRepositoryName', null), + + array('parseFormat', 'test'), + array('parseFormat', null, new \RuntimeException('Please pass the format of the code coverage via the "--format" option, i.e. "--format=php-clover"')), + ); + } + + public function providerTestExecute() + { + return array( + array(true, '200'), + array(false, '200'), + + array(true, '403'), + array(false, '403'), + + array(true, '500'), + array(false, '500'), + ); + } + + /** + * + * @param string $methode + * @return mixed expectedValue + */ + protected function helperMockRepositoryIntrospector($methode) + { + $this->getTempDir(true, 0777); + if ($methode === 'parseRepositoryName') { + $this->cloneRepository('https://github.com/schmittjoh/metadata.git'); + } else { + $this->installRepository(); + } + chdir($this->currentTmpDir); + + $repositoryIntrospector = new RepositoryIntrospector($this->currentTmpDir); + + file_put_contents($this->currentTmpDir.'/foo', 'foo'); + $this->exec('git add . && git commit -m "adds foo"', $this->currentTmpDir); + + switch ($methode) { + case "parseParents": + return $repositoryIntrospector->getCurrentParents(); + break; + case "parseRevision": + return $repositoryIntrospector->getCurrentRevision(); + break; + case "parseRepositoryName": + return $repositoryIntrospector->getQualifiedName(); + break; + } + } + protected function helperMockGeneratePostData($withCoverage, $revision = null) + { + $this->getTempDir(true, 0777); + $this->installRepository(); + chdir($this->currentTmpDir); + + + $buildDir = $this->currentTmpDir . DIRECTORY_SEPARATOR . 'build'; + mkdir($buildDir, 0777, true); + + + $coverageFile = $buildDir . DIRECTORY_SEPARATOR . 'coverage.xml'; + + $this->inputGetOptionMap[] = array('revision', $revision); + $this->inputGetOptionMap[] = array('parent', array()); + $this->inputGetOptionMap[] = array('format', "--format=php-clover"); + + $this->input->expects($this->any()) + ->method('getArgument') + ->with('coverage-file') + ->will($this->returnValue($coverageFile)); + + + file_put_contents($this->currentTmpDir.'/foo', 'foo'); + $this->exec('git add . && git commit -m "adds foo"', $this->currentTmpDir); + + + if ($withCoverage) { + file_put_contents( + $coverageFile, + sprintf( + '' . + '', + $this->currentTmpDir + ) + ); + } + } +} diff --git a/tests/Scrutinizer/Tests/Ocular/Command/SelfUpdateCommandTest.php b/tests/Scrutinizer/Tests/Ocular/Command/SelfUpdateCommandTest.php new file mode 100644 index 0000000..e4843e7 --- /dev/null +++ b/tests/Scrutinizer/Tests/Ocular/Command/SelfUpdateCommandTest.php @@ -0,0 +1,84 @@ +SUT = new SelfUpdateCommand(); + + $this->input = $this->getMock('\Symfony\Component\Console\Input\InputInterface'); + $this->output = $this->getMock('\Symfony\Component\Console\Output\OutputInterface'); + } + + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage The "self-update" command is only available for compiled phar files which you can obtain at "https://scrutinizer-ci.com/ocular.phar". + * + */ + public function testExecuteWithNonCompiledVersion() + { + $reflection = $this->helperReflectionMethode($this->SUT, 'execute'); + $reflection->invoke($this->SUT, $this->input, $this->output); + } + + public function testExecuteWithOfflineRevisionValue() + { + $this->markTestIncomplete(); + } + + public function testExecuteUp2Date() + { + $this->markTestIncomplete(); + } + + public function testExecuteCanNotDownload() + { + $this->markTestIncomplete(); + } + + public function testExecuteCanNotDeployNewVersion() + { + $this->markTestIncomplete(); + } + + public function testExecuteWorkFine() + { + $this->markTestIncomplete(); + } + + public function testConfigure() + { + $this->assertEquals('self-update', $this->SUT->getName()); + $this->assertGreaterThan(2, strlen($this->SUT->getDescription())); + } + + protected function helperReflectionMethode($object, $methodeName) + { + $reflection = new \ReflectionMethod($object, $methodeName); + $reflection->setAccessible(true); + + return $reflection; + } +} diff --git a/tests/Scrutinizer/Tests/Ocular/ConfigurationTest.php b/tests/Scrutinizer/Tests/Ocular/ConfigurationTest.php new file mode 100644 index 0000000..75776df --- /dev/null +++ b/tests/Scrutinizer/Tests/Ocular/ConfigurationTest.php @@ -0,0 +1,33 @@ +getAccessToken(); + + $this->assertInstanceOf($instance, $token); + if (!is_null($accessToken)) { + $this->assertEquals($accessToken, $token->get()); + } + } + + public function providerTestConfiguration() + { + return array( + array('accesss key for', '\PhpOption\Some'), + array(null, '\PhpOption\None'), + ); + } +} diff --git a/tests/Scrutinizer/Tests/Ocular/OcularTest.php b/tests/Scrutinizer/Tests/Ocular/OcularTest.php new file mode 100644 index 0000000..a628e25 --- /dev/null +++ b/tests/Scrutinizer/Tests/Ocular/OcularTest.php @@ -0,0 +1,95 @@ +SUT = new Ocular(); + } + + + public function testGetDefaultInputDefinition() + { + $definition = $this->SUT->getDefinition(); + + $optionsList = array( + // name, isRequired, isArray + array('access-token', true, false), + ); + + foreach ($optionsList as $option) { + $this->assertTrue($definition->hasOption($option[0])); + $optionObj = $definition->getOption($option[0]); + + $this->assertInstanceOf('\Symfony\Component\Console\Input\InputOption', $optionObj); + $this->assertEquals($option[0], $optionObj->getName()); + $this->assertSame($option[1], $optionObj->isValueRequired()); + $this->assertSame(!$option[1], $optionObj->isValueOptional()); + + $this->assertSame($option[2], $optionObj->isArray()); + } + } + + public function testRegisterCommands() + { + // setup + $registerCommands = $this->helperReflectionMethode($this->SUT, 'registerCommands'); + + $commands = $this->helperReflectionProperty($this->SUT, 'commands'); + $commands->setValue($this->SUT, array()); + $this->assertCount(0, $commands->getValue($this->SUT)); + + // run + $registerCommands->invoke($this->SUT); + + // assert + $this->assertNotCount(0, $commands->getValue($this->SUT)); + $this->assertCount(2, $commands->getValue($this->SUT)); + + $assertCommands = array( + 'code-coverage:upload' => '\Scrutinizer\Ocular\Command\CodeCoverage\UploadCommand', + 'self-update' => '\Scrutinizer\Ocular\Command\SelfUpdateCommand', + ); + foreach ($assertCommands as $commandName => $commandClass) { + $this->assertTrue($this->SUT->has($commandName)); + $this->assertInstanceOf($commandClass, $this->SUT->get($commandName)); + } + } + /** + * + * @dataProvider providerTrueFalse + */ + public function testLoadConfiguration($withConfigFile) + { + if ($withConfigFile) { + putenv('HOME=' . __DIR__ . '/_files'); + } else { + putenv('HOME=' . __DIR__); + } + + $loadConfiguration = $this->helperReflectionMethode($this->SUT, 'loadConfiguration'); + $result = $loadConfiguration->invoke($this->SUT); + + $this->assertInstanceOf('\Scrutinizer\Ocular\Configuration', $result); + $this->assertInstanceOf($withConfigFile ? '\PhpOption\Some' : '\PhpOption\None', $result->getAccessToken()); + } + + public function providerTrueFalse () + { + return array( + array(true), + array(false) + ); + } +} diff --git a/tests/Scrutinizer/Tests/Ocular/Util/RepositoryIntrospectorTest.php b/tests/Scrutinizer/Tests/Ocular/Util/RepositoryIntrospectorTest.php index 198beba..3068704 100644 --- a/tests/Scrutinizer/Tests/Ocular/Util/RepositoryIntrospectorTest.php +++ b/tests/Scrutinizer/Tests/Ocular/Util/RepositoryIntrospectorTest.php @@ -3,71 +3,141 @@ namespace Scrutinizer\Tests\Ocular\Util; use Scrutinizer\Ocular\Util\RepositoryIntrospector; +use Scrutinizer\Tests\Ocular\AbstractTestCaseClass; + use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Process\Exception\ProcessFailedException; -use Symfony\Component\Process\Process; -class RepositoryInspectorTest extends \PHPUnit_Framework_TestCase +class RepositoryInspectorTest extends AbstractTestCaseClass { - private $tmpDirs = array(); + + public function setUp() + { + $this->getTempDir(true, 0777); + } + + /** + * @expectedException \Symfony\Component\Process\Exception\ProcessFailedException + */ + public function testGetQualifiedNameNonGitRepo() + { + $introspector = new RepositoryIntrospector($this->currentTmpDir); + $introspector->getQualifiedName(); + } + + + /** + * @expectedException \RuntimeException + */ + public function testGetQualifiedNameWithNoRemote() + { + $this->installRepository(); + + $introspector = new RepositoryIntrospector($this->currentTmpDir); + $introspector->getQualifiedName(); + } public function testGetQualifiedName() { - $tmpDir = $this->getTempDir(); - $this->installRepository('https://github.com/schmittjoh/metadata.git', $tmpDir); + $this->cloneRepository('https://github.com/schmittjoh/metadata.git'); - $introspector = new RepositoryIntrospector($tmpDir); + $introspector = new RepositoryIntrospector($this->currentTmpDir); $this->assertEquals('g/schmittjoh/metadata', $introspector->getQualifiedName()); } + public function testGetCurrentRevision() + { + $this->installRepository(); + + file_put_contents($this->currentTmpDir.'/foo', 'foo'); + $this->exec('git add . && git commit -m "adds foo"', $this->currentTmpDir); + + $expectedRev = $this->exec('git rev-parse HEAD', $this->currentTmpDir); + + $introspector = new RepositoryIntrospector($this->currentTmpDir); + $headRev = $introspector->getCurrentRevision(); + + $this->assertInternalType('string', $headRev); + $this->assertEquals($expectedRev, $headRev); + } + + /** + * @expectedException \Symfony\Component\Process\Exception\ProcessFailedException + */ + public function testGetCurrentRevisionFail() + { + $this->installRepository(); + + $introspector = new RepositoryIntrospector($this->currentTmpDir); + $headRev = $introspector->getCurrentRevision(); + } + + /** + * @depends testGetCurrentRevision + */ public function testGetCurrentParents() { - $tmpDir = $this->getTempDir(); - mkdir($tmpDir, 0777, true); + $this->installRepository(); - $this->exec('git init', $tmpDir); - file_put_contents($tmpDir.'/foo', 'foo'); - $this->exec('git add . && git commit -m "adds foo"', $tmpDir); + file_put_contents($this->currentTmpDir.'/foo', 'foo'); + $this->exec('git add . && git commit -m "adds foo"', $this->currentTmpDir); - $introspector = new RepositoryIntrospector($tmpDir); + $introspector = new RepositoryIntrospector($this->currentTmpDir); $headRev = $introspector->getCurrentRevision(); - file_put_contents($tmpDir.'/bar', 'bar'); - $this->exec('git add . && git commit -m "adds bar"', $tmpDir); + file_put_contents($this->currentTmpDir.'/bar', 'bar'); + $this->exec('git add . && git commit -m "adds bar"', $this->currentTmpDir); $this->assertEquals(array($headRev), $introspector->getCurrentParents()); } - protected function tearDown() + /** + * @expectedException \Symfony\Component\Process\Exception\ProcessFailedException + */ + public function testGetCurrentParentsFail() { - parent::tearDown(); + $this->installRepository(); - $fs = new Filesystem(); - foreach ($this->tmpDirs as $dir) { - $fs->remove($dir); - } + $introspector = new RepositoryIntrospector($this->currentTmpDir); + + $introspector->getCurrentParents(); } - private function exec($cmd, $dir) + /** + * + * @dataProvider providerTestGetRepositoryType + */ + public function testGetRepositoryType($hosts, $exceptionName) { - $proc = new Process($cmd, $dir); - if ($proc->run() !== 0) { - throw new ProcessFailedException($proc); + if (strlen($exceptionName) > 1) { + $this->setExpectedException($exceptionName); } + + $tmpDir = $this->getTempDir(); + mkdir($tmpDir, 0777, true); + $introspector = new RepositoryIntrospector($tmpDir); + + $reflection = new \ReflectionMethod($introspector, 'getRepositoryType'); + $reflection->setAccessible(true); + $result = $reflection->invoke($introspector, $hosts); + + $this->assertEquals($exceptionName, $result); } - private function getTempDir() + protected function tearDown() { - $tmpDir = tempnam(sys_get_temp_dir(), 'ocular-intro'); - unlink($tmpDir); + parent::tearDown(); - return $this->tmpDirs[] = $tmpDir; + $fs = new Filesystem(); + foreach ($this->tmpDirs as $dir) { + $fs->remove($dir); + } } - private function installRepository($url, $dir) + public function providerTestGetRepositoryType() { - $proc = new Process('git clone '.$url.' '.$dir); - if (0 !== $proc->run()) { - throw new ProcessFailedException($proc); - } + return array( + array('github.com','g'), + array('bitbucket.org','b'), + array('gitlab.com','\LogicException') + ); } } diff --git a/tests/Scrutinizer/Tests/Ocular/_files/.ocular/config.json b/tests/Scrutinizer/Tests/Ocular/_files/.ocular/config.json new file mode 100644 index 0000000..368e3df --- /dev/null +++ b/tests/Scrutinizer/Tests/Ocular/_files/.ocular/config.json @@ -0,0 +1,3 @@ +{ + "access_token":"foobar" +} \ No newline at end of file diff --git a/tests/_files/_route-script.php b/tests/_files/_route-script.php new file mode 100644 index 0000000..4851466 --- /dev/null +++ b/tests/_files/_route-script.php @@ -0,0 +1,11 @@ +.*)/data/code-coverage#', $_SERVER["REQUEST_URI"], $urlMatches)) { + require 'code-coverage.php'; +} else { + echo "testtest2"; +} diff --git a/tests/_files/code-coverage.php b/tests/_files/code-coverage.php new file mode 100644 index 0000000..2cf23e6 --- /dev/null +++ b/tests/_files/code-coverage.php @@ -0,0 +1,27 @@ +$_GET, +// 'post'=>$_POST, +// 'inarray'=>in_array(md5('success'), $_REQUEST['access_token']), +// 'is1'=>md5('success') === $_REQUEST['access_token'][0], +// 'is2'=>md5('success') === $_REQUEST['access_token'][1] +); + +if (!in_array(md5('success'), $_REQUEST['access_token'])) { + header('HTTP/1.1 403 NO ACCESS'); + echo sprintf('no access with the token "%s"', var_export($_REQUEST['access_token'], true)); + exit; +} +if (isset($_POST['not_found'])) { + header('HTTP/1.1 404 NOT FOUND'); +} +if ($urlMatches['repoName'] === 'with-internal-server-error') { + header('HTTP/1.1 500 INTERNEL SERVER ERROR'); + echo "error"; + exit; +} + + +echo json_encode($response); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 80370a2..f8999d5 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,5 +1,8 @@ -add('Scrutinizer\Tests\Ocular', __DIR__); + + +\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists'); diff --git a/phpunit.xml.dist b/tests/phpunit.xml similarity index 58% rename from phpunit.xml.dist rename to tests/phpunit.xml index 7e5613a..d3aa1cf 100644 --- a/phpunit.xml.dist +++ b/tests/phpunit.xml @@ -2,6 +2,7 @@ - ./tests + ./Scrutinizer @@ -23,4 +23,15 @@ performance + + + + ../src + + + + + + +