Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into 4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jun 17, 2024
2 parents cde3c7d + 24a7673 commit 33bd537
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-apidocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Build API in source repo
working-directory: source
run: |
php tools/phpDocumentor run --ansi --verbose
php tools/phpDocumentor --ansi --verbose
cp -R ${GITHUB_WORKSPACE}/source/api/build/* ${GITHUB_WORKSPACE}/api/docs
- name: Deploy to API repo
Expand Down
14 changes: 14 additions & 0 deletions system/Commands/Database/MigrateRollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\Database\MigrationRunner;
use Throwable;

/**
Expand Down Expand Up @@ -78,10 +79,23 @@ public function run(array $params)
// @codeCoverageIgnoreEnd
}

/** @var MigrationRunner $runner */
$runner = service('migrations');

try {
$batch = $params['b'] ?? CLI::getOption('b') ?? $runner->getLastBatch() - 1;

if (is_string($batch)) {
if (! ctype_digit($batch)) {
CLI::error('Invalid batch number: ' . $batch, 'light_gray', 'red');
CLI::newLine();

return EXIT_ERROR;
}

$batch = (int) $batch;
}

CLI::write(lang('Migrations.rollingBack') . ' ' . $batch, 'yellow');

if (! $runner->regress($batch)) {
Expand Down
4 changes: 4 additions & 0 deletions system/Router/DefinedRouteCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public function collect(): Generator
$routes = $this->routeCollection->getRoutes($method);

foreach ($routes as $route => $handler) {
// The route key should be a string, but it is stored as an array key,
// it might be an integer.
$route = (string) $route;

if (is_string($handler) || $handler instanceof Closure) {
if ($handler instanceof Closure) {
$view = $this->routeCollection->getRoutesOptions($route, $method)['view'] ?? false;
Expand Down
18 changes: 18 additions & 0 deletions tests/system/Commands/DatabaseCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ public function testMigrate(): void
$this->assertStringContainsString('Migrations complete.', $this->getBuffer());
}

public function testMigrateRollbackValidBatchNumber(): void
{
command('migrate --all');
$this->clearBuffer();

command('migrate:rollback -b 1');
$this->assertStringContainsString('Done rolling back migrations.', $this->getBuffer());
}

public function testMigrateRollbackInvalidBatchNumber(): void
{
command('migrate --all');
$this->clearBuffer();

command('migrate:rollback -b x');
$this->assertStringContainsString('Invalid batch number: x', $this->getBuffer());
}

public function testMigrateRollback(): void
{
command('migrate --all -g tests');
Expand Down
14 changes: 14 additions & 0 deletions tests/system/Router/DefinedRouteCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ public function testCollect(): void
{
$routes = $this->createRouteCollection();
$routes->get('journals', 'Blogs');
$routes->get('100', 'Home::index');
$routes->get('product/(:num)', 'Catalog::productLookupByID/$1');
$routes->get('feed', static fn () => 'A Closure route.');
$routes->get('200', static fn () => 'A Closure route.');
$routes->view('about', 'pages/about');

$collector = new DefinedRouteCollector($routes);
Expand All @@ -69,6 +71,12 @@ public function testCollect(): void
'name' => 'journals',
'handler' => '\App\Controllers\Blogs',
],
[
'method' => 'GET',
'route' => '100',
'name' => '100',
'handler' => '\App\Controllers\Home::index',
],
[
'method' => 'GET',
'route' => 'product/([0-9]+)',
Expand All @@ -81,6 +89,12 @@ public function testCollect(): void
'name' => 'feed',
'handler' => '(Closure)',
],
[
'method' => 'GET',
'route' => '200',
'name' => '200',
'handler' => '(Closure)',
],
[
'method' => 'GET',
'route' => 'about',
Expand Down

0 comments on commit 33bd537

Please sign in to comment.