Skip to content
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
34 changes: 34 additions & 0 deletions console/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,47 @@ protected function interact(InputInterface $input, OutputInterface $output)

$this->helper = $this->getHelper('question');

$this->display_banner();

$output->writeln($this->language->lang('SKELETON_CLI_COMPOSER_QUESTIONS'));
$this->get_composer_data();

$output->writeln($this->language->lang('SKELETON_CLI_COMPONENT_QUESTIONS'));
$this->get_component_data();
}

/**
* Display a colorful ASCII art title banner.
*/
protected function display_banner(): void
{
$title_lines = [
[' _____ __ __ __ ', 'cyan'],
[' / ___// /_____ / /__ / /_____ ____ ', 'cyan'],
[' \__ \/ //_/ _ \/ / _ \/ __/ __ \/ __ \ ', 'blue'],
[' ___/ / ,< / __/ / __/ /_/ /_/ / / / / ', 'blue'],
[' /____/_/|_|\___/_/\___/\__/\____/_/ /_/ ', 'magenta'],
[' ______ __ _ ', 'magenta'],
[' / ____/ __/ /____ ____ _____(_)___ ____ ', 'red'],
[' / __/ | |/_/ __/ _ \/ __ \/ ___/ / __ \/ __ \ ', 'red'],
[' / /____> </ /_/ __/ / / (__ ) / /_/ / / / / ', 'yellow'],
['/_____/_/|_|\__/\___/_/ /_/____/_/\____/_/ /_/ ', 'yellow'],
];

$desc = $this->language->lang('SKELETON_CLI_BANNER_DESC');
$line = str_repeat('─', 50);

$this->output->writeln('');
foreach ($title_lines as [$text, $color])
{
$this->output->writeln("<fg=$color;options=bold>$text</>");
}
$this->output->writeln('');
$this->output->writeln("<fg=cyan> $desc </>");
$this->output->writeln("<fg=white>$line</>");
$this->output->writeln('');
}

/**
* Get composer data from the user
*/
Expand Down
21 changes: 17 additions & 4 deletions ext.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ protected function phpbb_requirement($phpBB_version = PHPBB_VERSION)
{
if (phpbb_version_compare($phpBB_version, self::MIN_PHPBB_ALLOWED, '<'))
{
$this->errors[] = 'PHPBB_VERSION_MIN_ERROR';
$this->errors[] = ['PHPBB_VERSION_MIN_ERROR', self::MIN_PHPBB_ALLOWED, $phpBB_version];
}
else if (phpbb_version_compare($phpBB_version, self::MAX_PHPBB_ALLOWED, '>='))
{
$this->errors[] = 'PHPBB_VERSION_MAX_ERROR';
$this->errors[] = ['PHPBB_VERSION_MAX_ERROR', self::MAX_PHPBB_ALLOWED, $phpBB_version];
}
}

Expand All @@ -71,7 +71,7 @@ protected function php_requirement($php_version = PHP_VERSION_ID)
{
if ($php_version < self::MIN_PHP_ALLOWED)
{
$this->errors[] = 'PHP_VERSION_ERROR';
$this->errors[] = ['PHP_VERSION_ERROR', $this->version_parse(self::MIN_PHP_ALLOWED), $this->version_parse($php_version)];
}
}

Expand Down Expand Up @@ -101,9 +101,22 @@ protected function enable_failed()
{
$language = $this->container->get('language');
$language->add_lang('common', 'phpbb/skeleton');
return array_map([$language, 'lang'], $this->errors);
return array_map(static function ($error) use ($language) {
return is_array($error) ? call_user_func_array([$language, 'lang'], $error) : $language->lang($error);
}, $this->errors);
}

return false;
}

/**
* Convert a version id (70100) to a semantic version (7.1.0)
*
* @param int $version
* @return string
*/
private function version_parse($version)
{
return sprintf('%d.%d.%d', $version / 10000, ($version / 100) % 100, $version % 100);
}
}
8 changes: 5 additions & 3 deletions language/en/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
'PHPBB_CREATE_SKELETON_EXPLAIN' => 'Generate your extension’s foundation in seconds. No more setting up files by hand — Skeleton builds it all for you, with clean, fully documented templates based on phpBB’s best practices. Before you begin, be sure to review the 📖 [<a href="%1$s" target="_blank">Skeleton Extension Documentation</a>], 🛡️ [<a href="%2$s" target="_blank">Extension Validation Rules</a>], and 🛠️ [<a href="%3$s" target="_blank">Coding Guidelines</a>].',
'PHPBB_SKELETON_EXT_HELP' => 'Learn More',

'SKELETON_CLI_BANNER_DESC' => 'The official phpBB skeleton extension generator',

'EXTENSION_CLI_SKELETON_SUCCESS' => "<info>Extension created successfully.\nCopy the extension from `store/tmp-ext/` into the `ext/` folder.</info>",
'SKELETON_CLI_COMPOSER_QUESTIONS' => '<comment>Enter composer.json details (hit enter to leave an option empty)</comment>',
'SKELETON_CLI_COMPONENT_QUESTIONS' => '<comment>Install optional components. Default: No; [y/n]</comment>',
Expand Down Expand Up @@ -161,7 +163,7 @@
'SKELETON_INVALID_PHPBB_MAX_VERSION'=> 'The maximum phpBB version requirement is invalid.',

'NO_ZIPARCHIVE_ERROR' => 'The ZipArchive class is required, but was not found in your PHP configuration.',
'PHP_VERSION_ERROR' => 'PHP 5.6 or newer is required to use this extension.',
'PHPBB_VERSION_MIN_ERROR' => 'phpBB 3.2.3 or newer is required to use this extension.',
'PHPBB_VERSION_MAX_ERROR' => 'phpBB 4 is not supported with this version of the extension. Please check for a newer version of this extension.'
'PHP_VERSION_ERROR' => 'PHP %1$s or newer is required to install this version of the Skeleton Extension. You are using PHP %2$s.',
'PHPBB_VERSION_MIN_ERROR' => 'phpBB %1$s or newer is required to install this version of the Skeleton Extension. You are using phpBB %2$s.',
'PHPBB_VERSION_MAX_ERROR' => 'phpBB %1$s or above is not supported by this version of the Skeleton Extension. You are using phpBB %2$s. Please check for a newer version of this extension.'
]);
40 changes: 36 additions & 4 deletions tests/ext_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,32 +97,57 @@ public function test_enable_failed_returns_expected()
$this->assertEquals(['LANG: SOME_ERROR'], $method->invoke($ext));
}

public function test_enable_failed_returns_parameterized_error()
{
$ext = $this->getMockBuilder(ext::class)
->disableOriginalConstructor()
->getMock();

$this->setExtErrors($ext, [['PHP_VERSION_ERROR', '7.1.0', '5.5.0']]);

$languageMock = $this->createMock(language::class);
$languageMock->method('add_lang')->willReturn(null);
$languageMock->method('lang')->willReturnCallback(function (...$args) {
return implode(':', $args);
});

$containerMock = $this->createMock(ContainerInterface::class);
$containerMock->method('get')->with('language')->willReturn($languageMock);

$this->setProperty($ext, 'container', $containerMock);

$method = (new \ReflectionClass($ext))->getMethod('enable_failed');
$method->setAccessible(true);

$this->assertEquals(['PHP_VERSION_ERROR:7.1.0:5.5.0'], $method->invoke($ext));
}

public function test_phpbb_requirement_min_error()
{
$this->setExtErrors($this->ext, []);
$this->invokeProtectedMethod($this->ext, 'phpbb_requirement', ['3.2.2']);
$this->assertContains('PHPBB_VERSION_MIN_ERROR', $this->getExtErrors($this->ext));
$this->assertContains('PHPBB_VERSION_MIN_ERROR', $this->getExtErrorKeys($this->ext));
}

public function test_phpbb_requirement_max_error()
{
$this->setExtErrors($this->ext, []);
$this->invokeProtectedMethod($this->ext, 'phpbb_requirement', ['4.0.0-dev']);
$this->assertContains('PHPBB_VERSION_MAX_ERROR', $this->getExtErrors($this->ext));
$this->assertContains('PHPBB_VERSION_MAX_ERROR', $this->getExtErrorKeys($this->ext));
}

public function test_php_requirement_error()
{
$this->setExtErrors($this->ext, []);
$this->invokeProtectedMethod($this->ext, 'php_requirement', [50500]);
$this->assertContains('PHP_VERSION_ERROR', $this->getExtErrors($this->ext));
$this->assertContains('PHP_VERSION_ERROR', $this->getExtErrorKeys($this->ext));
}

public function test_ziparchive_exists_error()
{
$this->setExtErrors($this->ext, []);
$this->invokeProtectedMethod($this->ext, 'ziparchive_exists', ['NotZipArchive']);
$this->assertContains('NO_ZIPARCHIVE_ERROR', $this->getExtErrors($this->ext));
$this->assertContains('NO_ZIPARCHIVE_ERROR', $this->getExtErrorKeys($this->ext));
}

// --- Helpers ---
Expand All @@ -141,6 +166,13 @@ protected function getExtErrors($ext): array
return $prop->getValue($ext);
}

protected function getExtErrorKeys($ext): array
{
return array_map(static function ($e) {
return is_array($e) ? $e[0] : $e;
}, $this->getExtErrors($ext));
}

protected function setExtErrors($ext, array $errors): void
{
$prop = (new \ReflectionClass($ext))->getProperty('errors');
Expand Down
Loading