Skip to content

Commit

Permalink
Lay the groundwork for Herd integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstauffer committed Aug 11, 2023
1 parent 4007d25 commit 582ddb2
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 7 deletions.
27 changes: 27 additions & 0 deletions cli/Valet/Context/Context.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Valet\Context;

abstract class Context
{
public static function assign()
{
if (static::isHerd()) {
return new Herd();
}

return new Standalone();
}

public static function isHerd()
{
return true; // @todo implement
}

public static function isStandalone()
{
return ! static::isHerd();
}

abstract public function name();
}
11 changes: 11 additions & 0 deletions cli/Valet/Context/Herd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Valet\Context;

class Herd extends Context
{
public function name()
{
return 'Laravel Herd';
}
}
11 changes: 11 additions & 0 deletions cli/Valet/Context/Standalone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Valet\Context;

class Standalone extends Context
{
public function name()
{
return 'Laravel Valet';
}
}
14 changes: 12 additions & 2 deletions cli/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Valet\Context\Context;
use Valet\Drivers\ValetDriver;
use function Valet\info;
use function Valet\output;
use function Valet\resolve;
use function Valet\table;
use function Valet\testing;
use function Valet\warning;
use function Valet\writer;

Expand All @@ -30,11 +33,18 @@
/**
* Create the application.
*/
Container::setInstance(new Container);

if (testing()) {
$container = Container::getInstance();
$context = resolve(Context::class);
} else {
Container::setInstance($container = new Container);
$container->instance(Context::class, $context = Context::assign());
}

$version = '4.1.3';

$app = new Application('Laravel Valet', $version);
$app = new Application($context->name(), $version);

$app->setDispatcher($dispatcher = new EventDispatcher());

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"autoload-dev": {
"files": [
"tests/UsesNullWriter.php",
"tests/PrepsContainer.php",
"tests/BaseApplicationTestCase.php",
"tests/Drivers/BaseDriverTestCase.php"
]
Expand Down
5 changes: 4 additions & 1 deletion tests/BaseApplicationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class BaseApplicationTestCase extends TestCase
{
use PrepsContainer;
use UsesNullWriter;

public function setUp(): void
Expand All @@ -25,7 +26,9 @@ public function tearDown(): void
public function prepTestConfig(): void
{
require_once __DIR__.'/../cli/includes/helpers.php';
Container::setInstance(new Container); // Reset app container from previous tests

// Reset app container from previous tests
$this->prepContainer();

if (Filesystem::isDir(VALET_HOME_PATH)) {
Filesystem::rmDirAndContents(VALET_HOME_PATH);
Expand Down
3 changes: 2 additions & 1 deletion tests/BrewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@

class BrewTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{
use PrepsContainer;
use UsesNullWriter;

public function set_up()
{
$_SERVER['SUDO_USER'] = user();

Container::setInstance(new Container);
$this->prepContainer();
$this->setNullWriter();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/NginxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@

class NginxTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{
use PrepsContainer;
use UsesNullWriter;

public function set_up()
{
$_SERVER['SUDO_USER'] = user();

Container::setInstance(new Container);
$this->prepContainer();
$this->setNullWriter();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/PhpFpmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@

class PhpFpmTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{
use PrepsContainer;
use UsesNullWriter;

public function set_up()
{
$_SERVER['SUDO_USER'] = user();

Container::setInstance(new Container);
$this->prepContainer();
$this->setNullWriter();
}

Expand Down
16 changes: 16 additions & 0 deletions tests/PrepsContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use Illuminate\Container\Container;
use Valet\Context\Context;
use Valet\Context\Standalone;
use function Valet\resolve;

trait PrepsContainer
{
public function prepContainer()
{
Container::setInstance($container = new Container);

$container->instance(Context::class, resolve(Standalone::class));
}
}
3 changes: 2 additions & 1 deletion tests/SiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@

class SiteTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{
use PrepsContainer;
use UsesNullWriter;

public function set_up()
{
$_SERVER['SUDO_USER'] = user();

Container::setInstance(new Container);
$this->prepContainer();
$this->setNullWriter();
}

Expand Down

0 comments on commit 582ddb2

Please sign in to comment.