Skip to content

Commit

Permalink
Added a NoopFileLocator
Browse files Browse the repository at this point in the history
The NoopFileLocator will be used as the default MintwareDe\NativeCron\Filesystem\CrontabFileLocatorInterface.
This change will fix the error when installing the bundle without configure the service before.
  • Loading branch information
devtronic committed Nov 10, 2022
1 parent 4187b8d commit fc990c0
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog

## v1.0.1
Added a NoopFileLocator to prevent errors when installing the bundle.

## v1.0.0
Initial release
3 changes: 3 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ services:

MintwareDe\NativeCron\CrontabManager:

MintwareDe\NativeCron\Filesystem\CrontabFileLocatorInterface:
class: MintwareDe\NativeCronBundle\Filesystem\NoopFileLocator

MintwareDe\NativeCron\Filesystem\FileHandlerInterface:
class: MintwareDe\NativeCron\Filesystem\FileHandler
27 changes: 27 additions & 0 deletions src/Filesystem/NoopFileLocator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace MintwareDe\NativeCronBundle\Filesystem;

use MintwareDe\NativeCron\Filesystem\CrontabFileLocatorInterface;

class NoopFileLocator implements CrontabFileLocatorInterface
{
public const EXCEPTION_MSG = 'You need to specify a CrontabFileLocatorInterface. Check the README at https://github.com/mintware-de/native-cron-bundle.';

public function locateDropInCrontab(string $name): string
{
throw new \Exception(self::EXCEPTION_MSG);
}

public function locateUserCrontab(string $username): string
{
throw new \Exception(self::EXCEPTION_MSG);
}

public function locateSystemCrontab(): string
{
throw new \Exception(self::EXCEPTION_MSG);
}
}
38 changes: 38 additions & 0 deletions tests/Filesystem/NoopFileLocatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace MintwareDe\NativeCronBundle\Tests\Filesystem;

use MintwareDe\NativeCron\Filesystem\CrontabFileLocatorInterface;
use MintwareDe\NativeCronBundle\Filesystem\NoopFileLocator;
use PHPUnit\Framework\TestCase;

class NoopFileLocatorTest extends TestCase
{
private NoopFileLocator $locator;

public function setUp(): void
{
$this->locator = new NoopFileLocator();
self::assertInstanceOf(CrontabFileLocatorInterface::class, $this->locator);

self::expectException(\Exception::class);
self::expectExceptionMessage(NoopFileLocator::EXCEPTION_MSG);
}

public function testLocateDropInCrontabShouldThrow(): void
{
$this->locator->locateDropInCrontab('');
}

public function testLocateUserCrontabShouldThrow(): void
{
$this->locator->locateUserCrontab('');
}

public function testLocateSystemCrontabShouldThrow(): void
{
$this->locator->locateSystemCrontab();
}
}

0 comments on commit fc990c0

Please sign in to comment.