Skip to content
  • Sponsor thecodingmachine/safe

  • Notifications You must be signed in to change notification settings
  • Fork 163

feat(chore): Adds download-docs command #697

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

Merged
merged 7 commits into from
May 16, 2025
Merged
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
10 changes: 5 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@ ARG XDEBUG_MODE=coverage
RUN apt update -y && apt install -y git composer php-cli php-dom php-curl php-xdebug vim
WORKDIR /app
RUN git config --global --add safe.directory /app && \
git config --global --add safe.directory /app/generator/doc/doc-en/en && \
git config --global --add safe.directory /app/generator/doc/doc-en/doc-base
CMD cd /app/generator/doc && ./update.sh && \
cd /app && composer install && \
cd /app/generator && composer install && php ./safe.php generate
git config --global --add safe.directory /app/generator/docs
CMD cd /app && composer install && \
cd /app/generator && composer install && \
php ./safe.php download-docs && \
php ./safe.php generate
4 changes: 2 additions & 2 deletions .github/workflows/auto-regenerate.yml
Original file line number Diff line number Diff line change
@@ -22,14 +22,14 @@ jobs:
- name: "Check out salathe/phpdoc-base"
uses: "actions/checkout@v4"
with:
path: "generator/doc/doc-en/doc-base"
path: "generator/docs/salathe/phpdoc-base"
repository: "salathe/phpdoc-base"
fetch-depth: 0

- name: "Check out php/doc-en"
uses: "actions/checkout@v4"
with:
path: "generator/doc/doc-en/en"
path: "generator/docs"
repository: "php/doc-en"
fetch-depth: 0

30 changes: 17 additions & 13 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -18,27 +18,31 @@ jobs:
steps:
- name: "Checkout"
uses: "actions/checkout@v4"

- name: "Get current date for the daily cache"
id: "date"
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT

- name: "Cache the php documentation"
id: cache-php-doc
id: cache-php-docs
uses: "actions/cache@v4"
with:
path: "generator/doc/doc-en"
key: php-doc-${{ steps.date.outputs.date }}
path: "generator/docs"
key: php-docs-${{ steps.date.outputs.date }}

- name: "Check out salathe/phpdoc-base"
uses: "actions/checkout@v4"
if: steps.cache-php-doc.outputs.cache-hit != 'true'
if: steps.cache-php-docs.outputs.cache-hit != 'true'
with:
path: "generator/doc/doc-en/doc-base"
path: "generator/docs/salathe/phpdoc-base"
repository: "salathe/phpdoc-base"
fetch-depth: 0

- name: "Check out php/doc-en"
uses: "actions/checkout@v4"
if: steps.cache-php-doc.outputs.cache-hit != 'true'
if: steps.cache-php-docs.outputs.cache-hit != 'true'
with:
path: "generator/doc/doc-en/en"
path: "generator/docs/php/doc-en"
repository: "php/doc-en"
fetch-depth: 0

@@ -61,11 +65,11 @@ jobs:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
- name: "Fetch cached docs"
id: cache-php-doc
id: cache-docs
uses: "actions/cache@v4"
with:
path: "generator/doc/doc-en"
key: php-doc-${{ needs.fetch_defs.outputs.date }}
path: "generator/docs"
key: php-docs-${{ needs.fetch_defs.outputs.date }}
fail-on-cache-miss: true
- name: "Cache dependencies installed with composer"
uses: "actions/cache@v4"
@@ -140,11 +144,11 @@ jobs:
coverage: "pcov"
php-version: "8.4"
- name: "Fetch cached docs"
id: cache-php-doc
id: cache-php-docs
uses: "actions/cache@v4"
with:
path: "generator/doc/doc-en"
key: php-doc-${{ needs.fetch_defs.outputs.date }}
path: "generator/docs"
key: php-docs-${{ needs.fetch_defs.outputs.date }}
fail-on-cache-miss: true
- name: "Cache dependencies installed with composer"
uses: "actions/cache@v4"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -7,3 +7,4 @@ vendor/
/generator/tests/rector/composer.lock
.phpunit.result.cache
.phpunit.cache
docs/
6 changes: 2 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -91,12 +91,10 @@ generator, as well as some handy shortcut shell scripts. You can use
The first step is to download the PHP documentation project locally, using git.

```bash
$ cd generator/doc
$ sh update.sh
$ generator/safe.php download-docs
```

The script can be used to both install the doc and to update it.
All it does is pull from theses mirrors:
This will download the PHP documentation from the official repository.

https://github.com/salathe/phpdoc-base

3 changes: 2 additions & 1 deletion generator/composer.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,8 @@
"phpstan/phpstan": "^2",
"symfony/console": "^7",
"symfony/process": "^7",
"symfony/finder": "^7"
"symfony/finder": "^7",
"symfony/filesystem": "^7.2"
},
"require-dev": {
"phpunit/phpunit": "^12",
68 changes: 67 additions & 1 deletion generator/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file removed generator/doc/entities/.gitkeep
Empty file.
11 changes: 0 additions & 11 deletions generator/doc/update.sh

This file was deleted.

2 changes: 2 additions & 0 deletions generator/safe.php
Original file line number Diff line number Diff line change
@@ -7,11 +7,13 @@
use Safe\Commands\FunctionInfoCommand;
use Safe\Commands\GenerateCommand;
use Safe\Commands\ScanObjectsCommand;
use Safe\Commands\DownloadDocsCommand;
use Symfony\Component\Console\Application;

$application = new Application();
$application->addCommands([new GenerateCommand()]);
$application->addCommands([new ScanObjectsCommand()]);
$application->addCommands([new FunctionInfoCommand()]);
$application->addCommands([new DownloadDocsCommand()]);

$application->run();
63 changes: 63 additions & 0 deletions generator/src/Commands/DownloadDocsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

namespace Safe\Commands;

use Safe\Filesystem\PathHelper;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressIndicator;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process;

final class DownloadDocsCommand extends Command
{
private SymfonyStyle $io;
private Filesystem $filesystem;

protected function configure(): void
{
$this
->setName('download-docs')
->setDescription('Download the recent version of the PHP documentation')
;
}

protected function initialize(InputInterface $input, OutputInterface $output): void
{
$this->io = new SymfonyStyle($input, $output);
$this->filesystem = new Filesystem();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->io->title($this->getDescription());

// Clean up before cloning.
$this->filesystem->remove(PathHelper::docsDirectory());
$this->filesystem->mkdir(PathHelper::docsDirectory());

$this->clone($output, 'salathe/phpdoc-base');
$this->clone($output, 'php/doc-en');

return self::SUCCESS;
}

private function clone(OutputInterface $output, string $repository): void
{
$progressIndicator = new ProgressIndicator($output);
$progressIndicator->start(\sprintf('Cloning <info>%s</info>', $repository));

$process = new Process(['git', 'clone', \sprintf('https://github.com/%s', $repository), \sprintf('%s/%s', PathHelper::docsDirectory(), $repository)]);
$process->start();

while ($process->isRunning()) {
$progressIndicator->advance();
}

$progressIndicator->finish(\sprintf('Downloaded <info>%s</info>', $repository));
}
}
2 changes: 1 addition & 1 deletion generator/src/Commands/FunctionInfoCommand.php
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$phpStanFunctionMapReader = new PhpStanFunctionMapReader();

$finder = new Finder();
$finder->in(DocPage::findReferenceDir() . "/*/functions/")->name($targetFilename)->sortByName();
$finder->in(DocPage::referenceDir() . "/*/functions/")->name($targetFilename)->sortByName();

foreach ($finder as $file) {
$docPage = new DocPage($file->getPathname());
11 changes: 6 additions & 5 deletions generator/src/Commands/GenerateCommand.php
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@

namespace Safe\Commands;

use Safe\Filesystem\PathHelper;
use Safe\XmlDocParser\Scanner;
use Safe\XmlDocParser\DocPage;
use Safe\Generator\FileCreator;
@@ -34,7 +35,7 @@ protected function execute(
$this->rmGenerated();

// Let's build the DTD necessary to load the XML files.
$this->checkout(DocPage::findReferenceDir(), "master");
$this->checkout(DocPage::referenceDir(), "master");
DocPage::buildEntities();

// PHP documentation is a living document, which broadly reflects
@@ -66,8 +67,8 @@ protected function execute(

// Scan the documentation for a given PHP version and find all
// functions that we need to generate safe wrappers for.
$this->checkout(DocPage::findReferenceDir(), $commit);
$scanner = new Scanner(DocPage::findReferenceDir());
$this->checkout(DocPage::referenceDir(), $commit);
$scanner = new Scanner(DocPage::referenceDir());
$res = $scanner->getMethods($scanner->getFunctionsPaths(), $pastFunctionNames, $output);
$output->writeln(
'Functions have been ignored and must be dealt with manually: ' .
@@ -133,8 +134,8 @@ private function rmGenerated(): void
}
}

if (\file_exists(DocPage::findDocDir() . '/entities/generated.ent')) {
\unlink(DocPage::findDocDir() . '/entities/generated.ent');
if (\file_exists(PathHelper::docsDirectory() . '/generated.ent')) {
\unlink(PathHelper::docsDirectory() . '/generated.ent');
}
}

2 changes: 1 addition & 1 deletion generator/src/Commands/ScanObjectsCommand.php
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$scanner = new Scanner(DocPage::findReferenceDir());
$scanner = new Scanner(DocPage::referenceDir());

$paths = $scanner->getMethodsPaths();

28 changes: 28 additions & 0 deletions generator/src/Filesystem/PathHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Safe\Filesystem;

final class PathHelper
{
public static function projectRootDir(): string
{
$path = realpath(__DIR__ . '/../../..');

if (false === $path) {
throw new \RuntimeException('Unable to locate root directory');
}

return $path;
}

public static function docsDirectory(): string
{
return \sprintf('%s/generator/docs', self::projectRootDir());
}

private function __construct()
{
}
}
24 changes: 10 additions & 14 deletions generator/src/XmlDocParser/DocPage.php
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@

namespace Safe\XmlDocParser;

use Safe\Filesystem\PathHelper;
use Safe\Generator\FileCreator;

use function explode;
@@ -15,14 +16,9 @@ public function __construct(private readonly string $path)
{
}

public static function findDocDir(): string
public static function referenceDir(): string
{
return __DIR__ . '/../../doc';
}

public static function findReferenceDir(): string
{
return DocPage::findDocDir() . '/doc-en/en/reference';
return PathHelper::docsDirectory().'/php/doc-en/reference';
}

// Ignore function if it was removed before PHP 8.1
@@ -116,10 +112,10 @@ public function loadAndResolveFile(): \SimpleXMLElement
throw new \RuntimeException('An error occurred while reading '.$this->path);
}
$strpos = \strpos($content, '?>')+2;
if (!\file_exists(DocPage::findDocDir() . '/entities/generated.ent')) {
if (!\file_exists(PathHelper::docsDirectory() . '/generated.ent')) {
self::buildEntities();
}
$path = \realpath(DocPage::findDocDir() . '/entities/generated.ent');
$path = \realpath(PathHelper::docsDirectory() . '/generated.ent');


$content = \substr($content, 0, $strpos)
@@ -188,14 +184,14 @@ private function arrayFlatten(array $array): array

public static function buildEntities(): void
{
$file1 = \file_get_contents(DocPage::findDocDir() . '/doc-en/en/language-defs.ent') ?: '';
$file2 = \file_get_contents(DocPage::findDocDir() . '/doc-en/en/language-snippets.ent') ?: '';
$file3 = \file_get_contents(DocPage::findDocDir() . '/doc-en/en/extensions.ent') ?: '';
$file4 = \file_get_contents(DocPage::findDocDir() . '/doc-en/doc-base/entities/global.ent') ?: '';
$file1 = \file_get_contents(PathHelper::docsDirectory() . '/php/doc-en/language-defs.ent') ?: '';
$file2 = \file_get_contents(PathHelper::docsDirectory() . '/php/doc-en/language-snippets.ent') ?: '';
$file3 = \file_get_contents(PathHelper::docsDirectory() . '/php/doc-en/extensions.ent') ?: '';
$file4 = \file_get_contents(PathHelper::docsDirectory() . '/salathe/phpdoc-base/entities/global.ent') ?: '';

$completeFile = $file1 . self::extractXmlHeader($file2) . self::extractXmlHeader($file3) . $file4;

\file_put_contents(DocPage::findDocDir() . '/entities/generated.ent', $completeFile);
\file_put_contents(PathHelper::docsDirectory() . '/generated.ent', $completeFile);
}

private static function extractXmlHeader(string $content): string
4 changes: 2 additions & 2 deletions generator/tests/Generator/WritePhpFunctionTest.php
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ class WritePhpFunctionTest extends TestCase
{
public function testGetPhpPrototypeFunctionRegular(): void
{
$docPage = new DocPage(DocPage::findReferenceDir() . '/pcre/functions/preg-match.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/pcre/functions/preg-match.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::FALSY);

@@ -25,7 +25,7 @@ public function testGetPhpPrototypeFunctionRegular(): void

public function testGetPhpPrototypeFunctionOverloaded(): void
{
$docPage = new DocPage(DocPage::findReferenceDir() . '/filesystem/functions/file-get-contents.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/filesystem/functions/file-get-contents.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::FALSY);

2 changes: 1 addition & 1 deletion generator/tests/XmlDocParser/DocPageTest.php
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ class DocPageTest extends TestCase
// take a documentation XML file path and return an ErrorType
private function d2e(string $path): ErrorType
{
return (new DocPage(DocPage::findReferenceDir() . "/" . $path))->getErrorType();
return (new DocPage(DocPage::referenceDir() . "/" . $path))->getErrorType();
}

public function testErrorTypeDetection(): void
34 changes: 17 additions & 17 deletions generator/tests/XmlDocParser/MethodTest.php
Original file line number Diff line number Diff line change
@@ -11,15 +11,15 @@ class MethodTest extends TestCase
{
public function testToString(): void
{
$docPage = new DocPage(DocPage::findReferenceDir() . '/pcre/functions/preg-match.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/pcre/functions/preg-match.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::FALSY);
$this->assertStringContainsString('Error type: FALSY', (string)$method);
}

public function testGetFunctionName(): void
{
$docPage = new DocPage(DocPage::findReferenceDir() . '/pcre/functions/preg-match.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/pcre/functions/preg-match.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::FALSY);
$name = $method->getFunctionName();
@@ -28,7 +28,7 @@ public function testGetFunctionName(): void

public function testGetFunctionType(): void
{
$docPage = new DocPage(DocPage::findReferenceDir() . '/pcre/functions/preg-match.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/pcre/functions/preg-match.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::FALSY);
$type = $method->getSignatureReturnType();
@@ -39,7 +39,7 @@ public function testGetFunctionType(): void

public function testGetFunctionParam(): void
{
$docPage = new DocPage(DocPage::findReferenceDir() . '/pcre/functions/preg-match.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/pcre/functions/preg-match.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::FALSY);
$params = $method->getParams();
@@ -49,7 +49,7 @@ public function testGetFunctionParam(): void

public function testGetTypeHintFromResource(): void
{
$docPage = new DocPage(DocPage::findReferenceDir() . '/strings/functions/sprintf.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/strings/functions/sprintf.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::FALSY);
$params = $method->getParams();
@@ -59,7 +59,7 @@ public function testGetTypeHintFromResource(): void
$this->assertTrue($params[1]->isVariadic());
$this->assertEquals('', $params[1]->getSignatureType());

$docPage = new DocPage(DocPage::findReferenceDir() . '/mbstring/functions/mb-ereg-replace-callback.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/mbstring/functions/mb-ereg-replace-callback.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::FALSY);
$params = $method->getParams();
@@ -69,7 +69,7 @@ public function testGetTypeHintFromResource(): void
$this->assertEquals('callable', $params[1]->getSignatureType());


$docPage = new DocPage(DocPage::findReferenceDir() . '/gmp/functions/gmp-export.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/gmp/functions/gmp-export.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::FALSY);
$params = $method->getParams();
@@ -78,7 +78,7 @@ public function testGetTypeHintFromResource(): void
$this->assertEquals('int', $params[1]->getDocBlockType());
$this->assertEquals('int', $params[1]->getSignatureType());

$docPage = new DocPage(DocPage::findReferenceDir() . '/hash/functions/hash-update.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/hash/functions/hash-update.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::FALSY);
$params = $method->getParams();
@@ -88,7 +88,7 @@ public function testGetTypeHintFromResource(): void

public function testImapOpen5Parameter(): void
{
$docPage = new DocPage(DocPage::findReferenceDir() . '/imap/functions/imap-open.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/imap/functions/imap-open.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::FALSY);
$params = $method->getParams();
@@ -98,7 +98,7 @@ public function testImapOpen5Parameter(): void

public function testGetInitializer(): void
{
$docPage = new DocPage(DocPage::findReferenceDir() . '/apache/functions/apache-getenv.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/apache/functions/apache-getenv.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::FALSY);

@@ -109,18 +109,18 @@ public function testGetInitializer(): void

public function testGetReturnDocBlock(): void
{
$docPage = new DocPage(DocPage::findReferenceDir() . '/array/functions/array-replace.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/array/functions/array-replace.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::NULLSY);
$this->assertEquals("@return array Returns an array.\n", $method->getReturnDocBlock());

$docPage = new DocPage(DocPage::findReferenceDir() . '/shmop/functions/shmop-delete.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/shmop/functions/shmop-delete.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::FALSY);
$this->assertEquals('', $method->getReturnDocBlock());
$this->assertEquals('void', $method->getSignatureReturnType());

$docPage = new DocPage(DocPage::findReferenceDir() . '/sqlsrv/functions/sqlsrv-next-result.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/sqlsrv/functions/sqlsrv-next-result.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::FALSY);
$this->assertEquals("@return bool|null Returns TRUE if the next result was successfully retrieved, FALSE if an error \n occurred, and NULL if there are no more results to retrieve.\n", $method->getReturnDocBlock());
@@ -129,28 +129,28 @@ public function testGetReturnDocBlock(): void

public function testGetPhpDoc(): void
{
$docPage = new DocPage(DocPage::findReferenceDir() . '/array/functions/array-replace.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/array/functions/array-replace.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::NULLSY);
$this->assertStringContainsString('@param array $array', $method->getPhpDoc());
}

public function testIsOverloaded(): void
{
$docPage = new DocPage(DocPage::findReferenceDir() . '/array/functions/array-all.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/array/functions/array-all.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::NULLSY);
$this->assertFalse($method->isOverloaded());

$docPage = new DocPage(DocPage::findReferenceDir() . '/filesystem/functions/file-get-contents.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/filesystem/functions/file-get-contents.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::NULLSY);
$this->assertTrue($method->isOverloaded());
}

public function testOpensslCipherKeyLengthUnionTypeReturnDocBlocks(): void
{
$docPage = new DocPage(DocPage::findReferenceDir() . '/openssl/functions/openssl-cipher-key-length.xml');
$docPage = new DocPage(DocPage::referenceDir() . '/openssl/functions/openssl-cipher-key-length.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::FALSY);
$this->assertEquals("@return int Returns the cipher length on success.\n", $method->getReturnDocBlock());
14 changes: 7 additions & 7 deletions generator/tests/XmlDocParser/ScannerTest.php
Original file line number Diff line number Diff line change
@@ -12,25 +12,25 @@ class ScannerTest extends TestCase

public function testGetMethodsPaths(): void
{
$scanner = new Scanner(DocPage::findReferenceDir());
$scanner = new Scanner(DocPage::referenceDir());
$paths = $scanner->getFunctionsPaths();

$this->assertArrayHasKey(DocPage::findReferenceDir() . '/filesystem/functions/chmod.xml', $paths);
$this->assertArrayNotHasKey(DocPage::findReferenceDir() . '/spl/appenditerator/getarrayiterator.xml', $paths);
$this->assertArrayHasKey(DocPage::referenceDir() . '/filesystem/functions/chmod.xml', $paths);
$this->assertArrayNotHasKey(DocPage::referenceDir() . '/spl/appenditerator/getarrayiterator.xml', $paths);
}

public function testGetFunctionsPaths(): void
{
$scanner = new Scanner(DocPage::findReferenceDir() . '/');
$scanner = new Scanner(DocPage::referenceDir() . '/');
$paths = $scanner->getMethodsPaths();

$this->assertArrayNotHasKey(DocPage::findReferenceDir() . '/filesystem/functions/chmod.xml', $paths);
$this->assertArrayHasKey(DocPage::findReferenceDir() . '/spl/appenditerator/getarrayiterator.xml', $paths);
$this->assertArrayNotHasKey(DocPage::referenceDir() . '/filesystem/functions/chmod.xml', $paths);
$this->assertArrayHasKey(DocPage::referenceDir() . '/spl/appenditerator/getarrayiterator.xml', $paths);
}

public function testGetMethods(): void
{
$scanner = new Scanner(DocPage::findReferenceDir());
$scanner = new Scanner(DocPage::referenceDir());
$functions = $scanner->getFunctionsPaths();
$testFunctions = [];
foreach ($functions as $name => $info) {