Skip to content

Commit

Permalink
Merge pull request #22 from michaelpetri/move-git-directories-under-var
Browse files Browse the repository at this point in the history
added fixed location for git dirs
  • Loading branch information
michaelpetri committed May 11, 2023
2 parents c4066ae + 76eb890 commit 1b9ab00
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 12 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"symfony/process": "^6.2.7",
"symfony/dependency-injection": "^6.2.7",
"symfony/framework-bundle": "^6.2.7",
"michaelpetri/php-git": "^0.4.1"
"michaelpetri/php-git": "^0.5.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.15.1",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/Application/DependencyInjection/TransportFactoryPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,32 @@

namespace MichaelPetri\SymfonyFileWatcher\Application\DependencyInjection;

use MichaelPetri\Git\Value\Directory;
use MichaelPetri\SymfonyFileWatcher\Infrastructure\Transport\FileWatcherFactory;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

final class TransportFactoryPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
$basePathId = \sprintf('%s<%s>', Directory::class, 'symfony_file_watcher.base_path');

$projectDir = Directory::from($container->get('%kernel.project_dir%'));

$container
->autowire($basePathId)
->setFactory([Directory::class, 'from'])
->setArguments([
$projectDir->sub('var')->path
]);

$container
->autowire(FileWatcherFactory::class, FileWatcherFactory::class)
->setArguments([
new Reference($basePathId)
])
->addTag('messenger.transport_factory');
}
}
9 changes: 9 additions & 0 deletions src/Infrastructure/Transport/FileWatcherFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@
namespace MichaelPetri\SymfonyFileWatcher\Infrastructure\Transport;

use MichaelPetri\Git\GitRepository;
use MichaelPetri\Git\Value\Directory;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;

final class FileWatcherFactory implements TransportFactoryInterface
{
public function __construct(
private readonly Directory $gitDirectoriesLocation
) {
}

public function createTransport(string $dsn, array $options = [], ?SerializerInterface $serializer = null): TransportInterface
{
$dsn = Dsn::fromString($dsn);

return new EventReceiver(
new GitRepository(
$dsn->directory,
$this->gitDirectoriesLocation
->sub('file-watcher-git')
->sub(\sha1($dsn->directory->path) . '.git'),
$dsn->timeout
)
);
Expand Down
10 changes: 7 additions & 3 deletions tests/Integration/Infrastructure/Transport/EventReceiverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,26 @@ protected function setUp(): void
{
parent::setUp();

$this->directory = Directory::from(\sys_get_temp_dir() . \DIRECTORY_SEPARATOR . 'EventReceiverTest');
$this->directory = Directory::from(\sys_get_temp_dir())->sub('EventReceiverTest');

$this->delete($this->directory);

$p = new Process(['mkdir', '-p', $this->directory->path]);
$p->mustRun();

$this->repository = new GitRepository($this->directory, Duration::inSeconds(60));
$this->repository = new GitRepository(
$this->directory,
$this->directory->sub('.git'),
Duration::inSeconds(60)
);
$this->receiver = new EventReceiver($this->repository);

$this->receiver->setup();
}

public function testSetup(): void
{
$gitDirectory = Directory::from($this->directory->path . \DIRECTORY_SEPARATOR . '.git');
$gitDirectory = $this->directory->sub('.git');

// Remove git file generated by test setup
$this->delete($gitDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tests\MichaelPetri\SymfonyFileWatcher\Integration\Infrastructure\Transport;

use MichaelPetri\Git\Value\Directory;
use MichaelPetri\SymfonyFileWatcher\Infrastructure\Transport\EventReceiver;
use MichaelPetri\SymfonyFileWatcher\Infrastructure\Transport\FileWatcherFactory;
use PHPUnit\Framework\TestCase;
Expand All @@ -17,7 +18,9 @@ protected function setUp(): void
{
parent::setUp();

$this->factory = new FileWatcherFactory();
$this->factory = new FileWatcherFactory(
Directory::from('/tmp/')
);
}

public function testSupports(): void
Expand Down

0 comments on commit 1b9ab00

Please sign in to comment.