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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

## [Unreleased]

### Added
- A message at the end of `php qt install:demo` that invites you to star Quantum on GitHub, with the link `https://github.com/quantum-php/framework`. It is shown only when the demo was created successfully (#194).
- The `common.star.message`, `common.star.button` and `common.star.badge_alt` texts, in English and Spanish, for the star block that the framework's `DemoWeb` About page shows. Without them the page shows the key names (#194).

### Fixed
- `php qt install:demo` no longer stops with "unable to get local issuer certificate" on a PHP that has no CA bundle configured: `save_remote_image()` and `save_remote_images()` download the public demo images with `CURLOPT_SSL_VERIFYPEER` off. The certificate of those downloads is not verified (#194).

## [3.1.0] - 2026-10-24

### Added
Expand Down
8 changes: 6 additions & 2 deletions helpers/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function save_remote_image(string $imageUrl, string $userDirectory, string $imag
$httpClient = httpRequest($imageUrl)
->setMethod('GET')
->setOpt(CURLOPT_FOLLOWLOCATION, true)
->setOpt(CURLOPT_SSL_VERIFYPEER, false) // public demo images only, so a PHP without a CA bundle still works
->start();

$fs->put(
Expand All @@ -104,8 +105,11 @@ function save_remote_images(array $images): array
}

$fs = FileSystemFactory::get();
$multiCurl = (new MultiCurlAdapter())
->setOpt(CURLOPT_FOLLOWLOCATION, true);
// The certificate is not verified: public demo images only, so a PHP without a CA bundle still works
$multiCurl = (new MultiCurlAdapter())->setOpts([
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => false,
]);
$jobs = [];
$imageNames = [];

Expand Down
15 changes: 14 additions & 1 deletion shared/Commands/DemoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ class DemoCommand extends CliCommand
*/
public const DEFAULT_PASSWORD = 'password';

/**
* Repository the visitors are asked to star
*/
public const REPOSITORY_URL = 'https://github.com/quantum-php/framework';

/**
* Message shown after the demo is created successfully, %1$s is the repository link
*/
public const STAR_MESSAGE = PHP_EOL
. '<fg=yellow;options=bold>★</> Would you like to show some love by starring Quantum on GitHub?' . PHP_EOL
. ' <href=%1$s;fg=cyan;options=underscore>%1$s</>';

/**
* Command name
* @var string|null
Expand Down Expand Up @@ -147,13 +159,14 @@ public function exec(): void

$progress->finish();
$this->info(PHP_EOL . 'Demo project created successfully');
$this->output(sprintf(self::STAR_MESSAGE, self::REPOSITORY_URL));
}

/**
* Provides the sequence of defined tasks to be executed.
* @return array[]
*/
private function getSteps(): array
protected function getSteps(): array
{
return [
[
Expand Down
7 changes: 7 additions & 0 deletions shared/resources/lang/en/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
'current_version' => 'Current version is: {%1}',
'cli_commands' => 'Quantum CLI Commands',

// ───── Star on GitHub ─────────────────────────────────────
'star' => [
'message' => 'Would you like to show some love by starring Quantum on GitHub?',
'button' => 'Star on GitHub',
'badge_alt' => 'GitHub stars',
],

// ───── Navigation ─────────────────────────────────────────
'home' => 'Home',
'about' => 'About',
Expand Down
7 changes: 7 additions & 0 deletions shared/resources/lang/es/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
'current_version' => 'La versión actual es: {%1}',
'cli_commands' => 'Comandos CLI de Quantum',

// ───── Star on GitHub ─────────────────────────────────────
'star' => [
'message' => '¿Te gustaría mostrar tu apoyo dando una estrella a Quantum en GitHub?',
'button' => 'Dar una estrella en GitHub',
'badge_alt' => 'Estrellas en GitHub',
],

// ───── Navigation ─────────────────────────────────────────
'home' => 'Inicio',
'about' => 'Acerca de',
Expand Down
156 changes: 156 additions & 0 deletions tests/Unit/shared/Commands/DemoCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?php

namespace Quantum\Tests\Unit\shared\Commands;

use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Application;
use Shared\Commands\DemoCommand;
use PHPUnit\Framework\TestCase;
use RuntimeException;

/**
* Runs the command with the given steps instead of the real demo installation
*/
class DemoCommandWithSteps extends DemoCommand
{
/**
* @var array<int, array{message: string, action: callable}>
*/
public array $steps = [];

protected function getSteps(): array
{
return $this->steps;
}
}

class DemoCommandTest extends TestCase
{
private const REPOSITORY_URL = 'https://github.com/quantum-php/framework';

public function testStarMessageIsShownAfterTheSuccessMessage(): void
{
$output = $this->runCommand(new DemoCommandWithSteps(), ['--yes' => true]);

$this->assertStringContainsString('Demo project created successfully', $output);
$this->assertStringContainsString(self::REPOSITORY_URL, $output);
$this->assertStringContainsString('starring Quantum on GitHub', $output);
$this->assertGreaterThan(
strpos($output, 'Demo project created successfully'),
strpos($output, self::REPOSITORY_URL)
);
}

public function testStarMessageLinkIsClickableInATerminal(): void
{
$output = $this->runCommand(new DemoCommandWithSteps(), ['--yes' => true], [], true);

$this->assertStringContainsString("\033]8;;" . self::REPOSITORY_URL . "\033\\", $output);
$this->assertStringContainsString(self::REPOSITORY_URL, $output);
$this->assertStringContainsString("\033]8;;\033\\", $output);
}

public function testStarMessageHasAColoredStarAndAnUnderlinedLink(): void
{
$output = $this->runCommand(new DemoCommandWithSteps(), ['--yes' => true], [], true);

$this->assertStringContainsString("\033[33;1m★\033[39;22m", $output);
$this->assertStringContainsString(
"\033[36;4m\033]8;;" . self::REPOSITORY_URL . "\033\\" . self::REPOSITORY_URL . "\033]8;;\033\\\033[39;24m",
$output
);
}

public function testStarMessageIsPlainTextWhenTheOutputIsNotATerminal(): void
{
$output = $this->runCommand(new DemoCommandWithSteps(), ['--yes' => true]);

$this->assertStringNotContainsString("\033", $output);
$this->assertStringNotContainsString('<href', $output);
$this->assertStringNotContainsString('<fg=', $output);
$this->assertStringContainsString('★ Would you like to show some love by starring Quantum on GitHub?', $output);
}

public function testStarMessageHasTheLinkOnItsOwnLineAfterABlankLine(): void
{
$output = $this->runCommand(new DemoCommandWithSteps(), ['--yes' => true]);

$this->assertMatchesRegularExpression(
'/Demo project created successfully\R\R★ [^\r\n]+\R {2}' . preg_quote(self::REPOSITORY_URL, '/') . '\R/',
$output
);
}

public function testStarMessageIsNotShownWhenTheOperationIsCancelled(): void
{
$output = $this->runCommand(new DemoCommandWithSteps(), [], ['no']);

$this->assertStringContainsString('Operation was canceled!', $output);
$this->assertStringNotContainsString(self::REPOSITORY_URL, $output);
}

public function testStarMessageIsNotShownWhenAStepFails(): void
{
$command = new DemoCommandWithSteps();
$command->steps = [
[
'message' => 'Failing step',
'action' => function (): void {
throw new RuntimeException('step failed');
},
],
];

$output = new BufferedOutput();

try {
$this->application($command)->run(new ArrayInput(['command' => 'install:demo', '--yes' => true]), $output);
$this->fail('The failing step did not stop the command');
} catch (RuntimeException $e) {
$this->assertSame('step failed', $e->getMessage());
}

$this->assertStringNotContainsString('Demo project created successfully', $output->fetch());
}

public function testStarMessageDoesNotUseTheOldRepositoryName(): void
{
$output = $this->runCommand(new DemoCommandWithSteps(), ['--yes' => true]);

$this->assertStringNotContainsString('softberg', $output);
}

/**
* @param array<string, mixed> $input
* @param array<int, string> $answers
*/
private function runCommand(DemoCommand $command, array $input, array $answers = [], bool $decorated = false): string
{
$output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, $decorated);

$arrayInput = new ArrayInput(['command' => 'install:demo'] + $input);
$arrayInput->setInteractive($answers !== []);

if ($answers !== []) {
$stream = fopen('php://memory', 'r+');
fwrite($stream, implode(PHP_EOL, $answers) . PHP_EOL);
rewind($stream);
$arrayInput->setStream($stream);
}

$this->application($command)->run($arrayInput, $output);

return $output->fetch();
}

private function application(DemoCommand $command): Application
{
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$application->add($command);

return $application;
}
}
60 changes: 60 additions & 0 deletions tests/Unit/shared/Lang/CommonLangTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Quantum\Tests\Unit\shared\Lang;

use PHPUnit\Framework\TestCase;

class CommonLangTest extends TestCase
{
/**
* @dataProvider languageProvider
*/
public function testEveryLanguageHasTheStarTexts(string $language): void
{
$star = $this->common($language)['star'] ?? null;

$this->assertIsArray($star);

foreach (['message', 'button', 'badge_alt'] as $key) {
$this->assertArrayHasKey($key, $star);
$this->assertIsString($star[$key]);
$this->assertNotSame('', trim($star[$key]));
}
}

public function testStarGroupHasTheSameKeysInEveryLanguage(): void
{
$this->assertSame(
array_keys($this->common('en')['star'] ?? []),
array_keys($this->common('es')['star'] ?? [])
);
}

public function testEnglishTextAsksForAStarOnGitHub(): void
{
$star = $this->common('en')['star'] ?? [];

$this->assertStringContainsString('starring Quantum on GitHub', (string) ($star['message'] ?? ''));
$this->assertSame('Star on GitHub', $star['button'] ?? null);
$this->assertSame('GitHub stars', $star['badge_alt'] ?? null);
}

/**
* @return array<string, array{0: string}>
*/
public static function languageProvider(): array
{
return [
'english' => ['en'],
'spanish' => ['es'],
];
}

/**
* @return array<string, mixed>
*/
private function common(string $language): array
{
return require dirname(__DIR__, 4) . '/shared/resources/lang/' . $language . '/common.php';
}
}
Loading