Skip to content
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
2 changes: 1 addition & 1 deletion bin/phpunit-check-annotation
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (!$autoloadFileFound) {

try {
$pathToTest = $argv[1];
$errors = (new \EdmondsCommerce\PHPQA\PHPUnit\CheckForLargeAndMediumAnnotations())->main($pathToTest);
$errors = (new \EdmondsCommerce\PHPQA\PHPUnit\CheckAnnotations())->main($pathToTest);
} catch (\RuntimeException $e) {
echo "\n".$e->getMessage()."\n";
exit(1);
Expand Down
1 change: 0 additions & 1 deletion qaConfig/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
timeoutForMediumTests="5"
timeoutForSmallTests="1"
timeoutForLargeTests="300"
failOnRisky="true"
>
<logging>
<log type="coverage-html" target="../var/qa/phpunit_coverage"/>
Expand Down
33 changes: 29 additions & 4 deletions src/Markdown/LinksChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,49 @@ public static function main(string $projectRootDirectory = null): int

private static function validateHttpLink(array $link, array &$errors, int &$return)
{
list(, $anchor, $link) = $link;
$context = stream_context_create(['http' => ['method' => 'HEAD']]);
list(, $anchor, $href) = $link;
static $checked = [];
$hashPos = strpos($href, '#');
if ($hashPos > 0) {
$href = substr($href, 0, $hashPos);
}
if (isset($checked[$href])) {
return;
}
$checked[$href] = true;
#$start = microtime(true);
#fwrite(STDERR, "\n".'Validating link: '.$href);
$context = stream_context_create([
'http' => [
'method' => 'HEAD',
'protocol_version' => 1.1,
'header' => [
'Connection: close',
],
],
]);
$result = null;
try {
$headers=get_headers($link, 0, $context);
$headers = get_headers($href, 0, $context);
foreach ($headers as $header) {
if (false !== strpos($header, ' 200 ')) {
#$time = round(microtime(true) - $start, 2);
#fwrite(STDERR, "\n".'OK ('.$time.' seconds): '.$href);

return;
}
}
} catch (\Throwable $e) {
}

$errors[] = \sprintf(
"\nBad link for \"%s\" to \"%s\"\nresult: %s\n",
$anchor,
$link,
$href,
var_export($result, true)
);
$return = 1;
#$time = round(microtime(true) - $start, 2);
#fwrite(STDERR, "\n".'Failed ('.$time.' seconds): '.$href);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @package EdmondsCommerce\PHPQA\PHPUnit
*/
class CheckForLargeAndMediumAnnotations
class CheckAnnotations
{
/**
* @var string
Expand All @@ -22,6 +22,11 @@ class CheckForLargeAndMediumAnnotations
*/
private $mediumPath;

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

/**
* @var array
*/
Expand All @@ -43,8 +48,10 @@ public function main(string $pathToTestsDirectory): array
}
$this->largePath = $pathToTestsDirectory.'/Large';
$this->mediumPath = $pathToTestsDirectory.'/Medium';
$this->smallPath = $pathToTestsDirectory.'/Small';
$this->checkLarge();
$this->checkMedium();
$this->checkSmall();

return $this->errors;
}
Expand All @@ -65,6 +72,14 @@ private function checkMedium(): void
$this->checkDirectory($this->mediumPath, 'medium');
}

private function checkSmall(): void
{
if (!is_dir($this->smallPath)) {
return;
}
$this->checkDirectory($this->smallPath, 'small');
}

private function checkDirectory(string $path, string $annotation)
{
foreach ($this->yieldTestFilesInPath($path) as $fileInfo) {
Expand Down
4 changes: 2 additions & 2 deletions src/PHPUnit/RerunCommandGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function main(string $junitLogPath = null): string
}


protected function load(string $contents)
private function load(string $contents)
{

libxml_use_internal_errors(true);
Expand All @@ -80,7 +80,7 @@ protected function load(string $contents)
* @throws \Exception
* @SuppressWarnings(PHPMD.StaticAccess)
*/
protected function getDefaultFilePath(): string
private function getDefaultFilePath(): string
{
return Helper::getProjectRootDirectory().'/var/qa/phpunit.junit.log.xml';
}
Expand Down
14 changes: 7 additions & 7 deletions src/Psr4Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class Psr4Validator
* @var array
*/
protected $decodedComposerJson;
private $parseErrors = [];
private $psr4Errors = [];
private $ignoreRegexPatterns;
private $ignoredFiles = [];
private $missingPaths = [];
private $parseErrors = [];
private $psr4Errors = [];
private $ignoreRegexPatterns;
private $ignoredFiles = [];
private $missingPaths = [];

/**
* Psr4Validator constructor.
Expand Down Expand Up @@ -108,7 +108,7 @@ private function getActualNamespace(\SplFileInfo $fileInfo): string
{
$contents = \file_get_contents($fileInfo->getPathname());
\preg_match('%namespace\s+?([^;]+)%', $contents, $matches);
if (empty($matches) || !isset($matches[1])) {
if (empty($matches)) {
$this->parseErrors[] = $fileInfo->getRealPath();

return '';
Expand Down Expand Up @@ -142,7 +142,7 @@ public function __construct(\RecursiveIteratorIterator $iterator)
}
}

public function compare($item1, $item2)
protected function compare($item1, $item2)
{
return strcmp($item2->getRealpath(), $item1->getRealpath());
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Small/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class HelperTest extends TestCase
/**
* @throws \Exception
* @covers ::getComposerJsonDecoded()
*
* @small
*/
public function testItCanGetComposerJsonDecode()
{
Expand All @@ -28,7 +28,7 @@ public function testItCanGetComposerJsonDecode()
/**
* @throws \Exception
* @covers ::getComposerJsonDecoded()
*
* @small
*/
public function testItWillThrowExceptionForInvalidComposerJson()
{
Expand All @@ -39,7 +39,7 @@ public function testItWillThrowExceptionForInvalidComposerJson()
/**
* @throws \Exception
* @covers ::getProjectRootDirectory()
*
* @small
*/
public function testGetProjectRoot()
{
Expand Down
8 changes: 4 additions & 4 deletions tests/Small/Markdown/LinksCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class LinksCheckerTest extends TestCase
* @throws \Exception
* @SuppressWarnings(PHPMD.StaticAccess)
* @covers \EdmondsCommerce\PHPQA\Markdown\LinksChecker
*
* @small
*/
public function testInvalidProject()
{
Expand All @@ -42,7 +42,7 @@ public function testInvalidProject()
* @throws \Exception
* @SuppressWarnings(PHPMD.StaticAccess)
* @covers \EdmondsCommerce\PHPQA\Markdown\LinksChecker
*
* @small
*/
public function testMainNoReadmeFile()
{
Expand All @@ -53,7 +53,7 @@ public function testMainNoReadmeFile()
/**
* @throws \Exception
* @covers \EdmondsCommerce\PHPQA\Markdown\LinksChecker
*
* @small
*/
public function testValidNoDocsFolder()
{
Expand All @@ -65,7 +65,7 @@ public function testValidNoDocsFolder()

/**
* @covers \EdmondsCommerce\PHPQA\Markdown\LinksChecker
*
* @small
*/
public function testItHandlesNonFileLinks()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,43 @@

namespace EdmondsCommerce\PHPQA\Tests\Small\PHPUnit;

use EdmondsCommerce\PHPQA\PHPUnit\CheckForLargeAndMediumAnnotations;
use EdmondsCommerce\PHPQA\PHPUnit\CheckAnnotations;
use PHPUnit\Framework\TestCase;

/**
* Class CheckForLargeAndMediumAnnotationsTest
*
* @coversDefaultClass \EdmondsCommerce\PHPQA\PHPUnit\CheckForLargeAndMediumAnnotations
* @coversDefaultClass \EdmondsCommerce\PHPQA\PHPUnit\CheckAnnotations
*
* @package EdmondsCommerce\PHPQA\Tests\Large\PHPUnit
*/
class CheckForLargeAndMediumAnnotationsTest extends TestCase
class CheckAnnotationsTest extends TestCase
{
/**
* @var CheckForLargeAndMediumAnnotations
* @var CheckAnnotations
*/
private $checker;

public function setup(): void
{
$this->checker = new CheckForLargeAndMediumAnnotations();
$this->checker = new CheckAnnotations();
}

/**
* @test
* @covers \EdmondsCommerce\PHPQA\PHPUnit\CheckForLargeAndMediumAnnotations
* @large
* @covers ::main()
* @small
*/
public function itThrowAnExceptionIfTestsPathIsInvalid()
{
$this->expectException(\InvalidArgumentException::class);
$this->checker->main('/invalid/path');
}

/**
* @test
* @covers \EdmondsCommerce\PHPQA\PHPUnit\CheckAnnotations
* @small
*/
public function itReturnsNoErrorsIfItsAllGood(): void
{
Expand All @@ -39,8 +50,25 @@ public function itReturnsNoErrorsIfItsAllGood(): void

/**
* @test
* @covers \EdmondsCommerce\PHPQA\PHPUnit\CheckForLargeAndMediumAnnotations
* @large
* @covers \EdmondsCommerce\PHPQA\PHPUnit\CheckAnnotations
* @small
*/
public function itFindsMissingSmallAnnotations(): void
{
$pathToTestsDirectory = __DIR__.'/../../assets/phpunitAnnotations/projectMissingSmall/tests';
$expected = [
'SomethingTest.php' => [
'Failed finding @small for method: itDoesSomething',
],
];
$actual = $this->checker->main($pathToTestsDirectory);
$this->assertSame($expected, $actual);
}

/**
* @test
* @covers \EdmondsCommerce\PHPQA\PHPUnit\CheckAnnotations
* @small
*/
public function itFindsMissingMediumAnnotations(): void
{
Expand All @@ -56,8 +84,8 @@ public function itFindsMissingMediumAnnotations(): void

/**
* @test
* @covers \EdmondsCommerce\PHPQA\PHPUnit\CheckForLargeAndMediumAnnotations
* @large
* @covers \EdmondsCommerce\PHPQA\PHPUnit\CheckAnnotations
* @small
*/
public function itFindsMissingLargeAnnotations(): void
{
Expand All @@ -73,8 +101,8 @@ public function itFindsMissingLargeAnnotations(): void

/**
* @test
* @covers \EdmondsCommerce\PHPQA\PHPUnit\CheckForLargeAndMediumAnnotations
* @large
* @covers \EdmondsCommerce\PHPQA\PHPUnit\CheckAnnotations
* @small
*/
public function itReturnsNoErrorsIfNotApplicableToProject(): void
{
Expand Down
10 changes: 5 additions & 5 deletions tests/Small/PHPUnit/RerunCommandGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RerunCommandGeneratorTest extends TestCase
{
/**
* @covers \EdmondsCommerce\PHPQA\PHPUnit\RerunCommandGenerator
*
* @small
*/
public function testCanParseFailuresAndErrors()
{
Expand All @@ -27,7 +27,7 @@ public function testCanParseFailuresAndErrors()

/**
* @covers \EdmondsCommerce\PHPQA\PHPUnit\RerunCommandGenerator
*
* @small
*/
public function testWillReturnNoFilterIfLogPathDoesNotExist()
{
Expand All @@ -38,7 +38,7 @@ public function testWillReturnNoFilterIfLogPathDoesNotExist()

/**
* @covers \EdmondsCommerce\PHPQA\PHPUnit\RerunCommandGenerator
*
* @small
*/
public function testWillReturnNoFilterIfLogIsEmpty()
{
Expand All @@ -49,7 +49,7 @@ public function testWillReturnNoFilterIfLogIsEmpty()

/**
* @covers \EdmondsCommerce\PHPQA\PHPUnit\RerunCommandGenerator
*
* @small
*/
public function testWillReturnNoFilterIfNoFailures()
{
Expand All @@ -60,7 +60,7 @@ public function testWillReturnNoFilterIfNoFailures()

/**
* @covers \EdmondsCommerce\PHPQA\PHPUnit\RerunCommandGenerator
*
* @small
*/
public function testItWillThrowExceptionIfXmlInvalid()
{
Expand Down
Loading