Skip to content

Commit

Permalink
Merge pull request #580 from hydephp/develop
Browse files Browse the repository at this point in the history
v1.2.1 - 2023-10-19
  • Loading branch information
caendesilva authored Oct 19, 2023
2 parents 1683b8d + c9cf6fa commit 36505de
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 11 deletions.
21 changes: 21 additions & 0 deletions src/Console/Commands/VendorPublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use function realpath;
use function sprintf;
use function str_replace;
use function Laravel\Prompts\select;

/**
* Publish any publishable assets from vendor packages.
Expand Down Expand Up @@ -42,6 +43,26 @@ public function handle(): void
ServiceProvider::$publishGroups = $originalGroups;
}

/**
* Our child method only uses the select function, instead of the search one.
*/
protected function promptForProviderOrTag(): void
{
$choices = $this->publishableChoices();

$choice = select(
"Which provider or tag's files would you like to publish?",
$choices,
scroll: 15,
);

if ($choice == $choices[0]) {
return;
}

$this->parseChoice($choice);
}

/**
* Write a status message to the console.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/HydeKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class HydeKernel implements SerializableContract
use Serializable;
use Macroable;

final public const VERSION = '1.1.0';
final public const VERSION = '1.2.1';

protected static self $instance;

Expand Down
14 changes: 12 additions & 2 deletions src/Framework/Features/Navigation/DropdownNavItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Hyde\Framework\Features\Navigation;

use Hyde\Facades\Config;
use Illuminate\Support\Collection;

use function collect;
Expand All @@ -19,9 +20,9 @@ class DropdownNavItem extends NavItem
public array $items;

/** @param array<NavItem> $items */
public function __construct(string $label, array $items)
public function __construct(string $label, array $items, ?int $priority = null)
{
parent::__construct('', $label, 999);
parent::__construct('', $label, $priority ?? $this->searchForDropdownPriorityInNavigationConfig($label) ?? 999);
$this->items = $items;
}

Expand All @@ -34,4 +35,13 @@ public function getItems(): Collection
{
return collect($this->items);
}

private function searchForDropdownPriorityInNavigationConfig(string $groupKey): ?int
{
return Config::getArray('hyde.navigation.order', [
'index' => 0,
'posts' => 10,
'docs/index' => 100,
])[$groupKey] ?? null;
}
}
2 changes: 1 addition & 1 deletion src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function unslash(string $string): string
use Illuminate\Contracts\Support\Arrayable;
use Symfony\Component\Yaml\Yaml;

use function function_exists;
use function function_exists;
use function array_merge;
use function str_replace;
use function implode;
Expand Down
17 changes: 14 additions & 3 deletions tests/Feature/Commands/VendorPublishCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function test_command_prompts_for_provider_or_tag()

$this->artisan('vendor:publish')
->expectsChoice('Which provider or tag\'s files would you like to publish?', 'Tag: example-configs', [
'<comment>Publish files from all providers and tags listed below</comment>',
'<fg=gray>Provider:</> ExampleProvider',
'<fg=gray>Tag:</> example-configs',
'All providers and tags',
])
->assertExitCode(0);
}
Expand All @@ -60,7 +60,7 @@ public function test_unhelpful_publishers_are_removed()

$this->artisan('vendor:publish')
->expectsChoice('Which provider or tag\'s files would you like to publish?', 'Tag: example-configs', [
'<comment>Publish files from all providers and tags listed below</comment>',
'All providers and tags',
])->assertExitCode(0);
}

Expand All @@ -73,11 +73,22 @@ public function test_config_group_is_renamed_to_be_more_helpful()

$this->artisan('vendor:publish')
->expectsChoice('Which provider or tag\'s files would you like to publish?', 'Tag: vendor-configs', [
'<comment>Publish files from all providers and tags listed below</comment>',
'All providers and tags',
'<fg=gray>Tag:</> vendor-configs',
])->assertExitCode(0);
}

public function test_can_select_default()
{
ServiceProvider::$publishes = [];
ServiceProvider::$publishGroups = [];

$this->artisan('vendor:publish')
->expectsChoice('Which provider or tag\'s files would you like to publish?', 'All providers and tags', [
'All providers and tags',
])->assertExitCode(0);
}

public function test_status_method()
{
$command = new StatusMethodTestClass($this->createMock(Filesystem::class));
Expand Down
28 changes: 24 additions & 4 deletions tests/Feature/HydeKernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Hyde\Framework\Testing\Feature;

use Throwable;
use Composer\InstalledVersions;
use Hyde\Facades\Features;
use Hyde\Foundation\Facades\Pages;
Expand Down Expand Up @@ -294,11 +295,30 @@ public function test_version_constant_is_a_valid_semver_string()
);
}

public function test_version_constant_is_up_to_date()
public function test_version_constant_is_up_to_date_with_composer()
{
$this->assertTrue(version_compare(
HydeKernel::VERSION, InstalledVersions::getPrettyVersion('hyde/framework')
) >= 0);
$version = InstalledVersions::getPrettyVersion('hyde/framework');

if (str_starts_with($version, 'dev-')) {
$this->markTestSkipped('Installed version is for development');
}

$this->assertSame(HydeKernel::VERSION, $version);
}

public function test_version_constant_is_up_to_date_with_git()
{
try {
$version = trim(shell_exec('git describe --abbrev=0 --tags'));
} catch (Throwable) {
$this->markTestSkipped('Could not get version from Git');
}

if ('v'.HydeKernel::VERSION === $version) {
$this->assertSame('v'.HydeKernel::VERSION, $version);
} else {
$this->markTestSkipped('Version constant does not match Git version!');
}
}

public function test_version_method_returns_version_constant()
Expand Down
30 changes: 30 additions & 0 deletions tests/Unit/DropdownNavItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Hyde\Framework\Testing\Unit;

use Hyde\Facades\Config;
use Hyde\Framework\Features\Navigation\DropdownNavItem;
use Hyde\Framework\Features\Navigation\NavItem;
use Hyde\Pages\MarkdownPage;
Expand Down Expand Up @@ -37,6 +38,21 @@ public function testConstruct()

$this->assertSame('foo', $item->label);
$this->assertSame([], $item->items);
$this->assertSame(999, $item->priority);
}

public function testConstructWithCustomPriority()
{
$item = new DropdownNavItem('foo', [], 500);

$this->assertSame(500, $item->priority);
}

public function testConstructWithNullPriority()
{
$item = new DropdownNavItem('foo', [], null);

$this->assertSame(999, $item->priority);
}

public function testFromArray()
Expand Down Expand Up @@ -72,4 +88,18 @@ public function testGetItems()
$item = DropdownNavItem::fromArray('foo', $children);
$this->assertSame($children, $item->getItems()->all());
}

public function testCanSetPriorityInConfig()
{
$root = Config::getFacadeRoot();
$mock = clone $root;
Config::swap($mock);

Config::set('hyde.navigation.order.foo', 500);
$item = new DropdownNavItem('foo', []);

$this->assertSame(500, $item->priority);

Config::swap($root);
}
}

0 comments on commit 36505de

Please sign in to comment.