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
19 changes: 19 additions & 0 deletions src/Tags/Installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,32 @@

class Installed extends Tags
{
/**
* Check if composer package is installed via {{ installed package="vendor/package" }}.
*
* @return string|void
*/
public function index()
{
if (! $package = $this->params->get('package')) {
return;
}

return $this->installed($package);
}

/**
* Check if composer package is installed via {{ installed:* }}.
*
* @param string $package
* @return string|void
*/
public function wildcard($package)
{
return $this->installed($package);
}

protected function installed($package)
{
$installed = Composer::isInstalled($package);

Expand Down
14 changes: 14 additions & 0 deletions tests/Tags/InstalledTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,18 @@ public function it_can_check_if_package_is_installed_using_tag_pair()
$this->assertEquals('yes', $this->tag('{{ installed:hasselhoff/baywatch-embeds }}yes{{ /installed:hasselhoff/baywatch-embeds }}'));
$this->assertEquals('', $this->tag('{{ installed:hasselhoff/lotr-embeds }}yes{{ /installed:hasselhoff/lotr-embeds }}'));
}

#[Test]
public function it_can_check_if_package_is_installed_using_param()
{
$this->assertEquals('yes', $this->tag('{{ installed package="hasselhoff/baywatch-embeds" }}yes{{ /installed }}'));
$this->assertEquals('', $this->tag('{{ installed package="hasselhoff/lotr-embeds" }}yes{{ /installed }}'));
}

#[Test]
public function it_outputs_empty_when_passing_nothing()
{
$this->assertEquals('', $this->tag('{{ installed package="" }}yes{{ /installed }}'));
$this->assertEquals('', $this->tag('{{ installed :package="null" }}yes{{ /installed }}'));
}
}
Loading