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
3 changes: 0 additions & 3 deletions .atoum.bootstrap.php

This file was deleted.

11 changes: 0 additions & 11 deletions .atoum.php

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Application CI

on: pull_request

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
tests:
runs-on: ubuntu-latest
name: PHP CI ${{ matrix.php-versions }}
strategy:
matrix:
php-versions:
- 8.3
- 8.4

steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: composer:v2
env:
runner: self-hosted
- name: Install dependencies
run: composer install --no-interaction --no-progress
- name: Run unit tests
run: ./bin/phpunit
23 changes: 23 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Static Analysis

on: pull_request

jobs:

phpcsfixer:
name: PHP Coding Standards Fixer
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP environment
uses: shivammathur/setup-php@v2
with:
php-version: 8.3

- name: Install dependencies
run: composer install --no-interaction --no-progress

- name: PHP Coding Standards Fixer
run: ./bin/php-cs-fixer fix --dry-run --diff
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

11 changes: 6 additions & 5 deletions Command/DeployActionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Psr\Log\LoggerInterface;
use Spy\Timeline\Driver\ActionManagerInterface;
use Spy\Timeline\Spread\Deployer;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -14,11 +15,12 @@
* This command will deploy each actions (see limit option) which
* has PUBLISHED on status_wanted.
*/
#[AsCommand(
name: 'spy_timeline:deploy',
description: 'Deploy on spreads for waiting action',
)]
class DeployActionCommand extends Command
{
protected static $defaultName = 'spy_timeline:deploy';
protected static $defaultDescription = 'Deploy on spreads for waiting action';

private ActionManagerInterface $actionManager;
private Deployer $deployer;
private LoggerInterface $logger;
Expand All @@ -36,10 +38,9 @@ public function __construct(
$this->logger = $logger;
}

protected function configure()
protected function configure(): void
{
$this
->setDescription(self::$defaultDescription)
->addOption('limit', 'l', InputOption::VALUE_OPTIONAL, 'How many actions will be deployed', 200)
;
}
Expand Down
13 changes: 5 additions & 8 deletions Command/SpreadListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
namespace Spy\TimelineBundle\Command;

use Spy\Timeline\Spread\Deployer;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* This command will show all services which are defined as spread.
*/
#[AsCommand(
name: 'spy_timeline:spreads',
description: 'Deploy on spreads for waiting action',
)]
class SpreadListCommand extends Command
{
protected static $defaultName = 'spy_timeline:spreads';
protected static $defaultDescription = 'Deploy on spreads for waiting action';

private Deployer $deployer;

public function __construct(
Expand All @@ -24,11 +26,6 @@ public function __construct(
$this->deployer = $deployer;
}

protected function configure()
{
$this->setDescription(self::$defaultDescription);
}

/**
* {@inheritdoc}
*/
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Configuration implements ConfigurationInterface
*
* @return TreeBuilder The tree builder
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$tb = new TreeBuilder('spy_timeline');
$rootNode = $tb->getRootNode();
Expand Down
55 changes: 55 additions & 0 deletions Tests/Units/Command/DeployActionCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Spy\TimelineBundle\Tests\Units\Command;

use PHPUnit\Framework\TestCase;
use Spy\TimelineBundle\Command\DeployActionCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;

class DeployActionCommandTest extends TestCase
{
public function testNoTimeline()
{
$actionManager = $this->createMock(\Spy\Timeline\Driver\ActionManagerInterface::class);
$deployer = $this->createMock(\Spy\Timeline\Spread\Deployer::class);
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);

$actionManager->method('findActionsWithStatusWantedPublished')->willReturn([]);

$command = new DeployActionCommand($actionManager, $deployer, $logger);

$application = new Application();
$application->add($command);

$command = $application->find('spy_timeline:deploy');

$commandTester = new CommandTester($command);
$commandTester->execute(['command' => $command->getName()], []);

$this->assertEquals('There is 0 action(s) to deploy'.PHP_EOL.'Done'.PHP_EOL, $commandTester->getDisplay());
}

public function testOneTimeline()
{
$actionManager = $this->createMock(\Spy\Timeline\Driver\ActionManagerInterface::class);
$deployer = $this->createMock(\Spy\Timeline\Spread\Deployer::class);
$action = $this->createMock(\Spy\Timeline\Model\ActionInterface::class);
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);

$action->method('getId')->willReturn(1);
$actionManager->method('findActionsWithStatusWantedPublished')->willReturn([$action]);

$command = new DeployActionCommand($actionManager, $deployer, $logger);

$application = new Application();
$application->add($command);

$command = $application->find('spy_timeline:deploy');

$commandTester = new CommandTester($command);
$commandTester->execute(['command' => $command->getName()], []);

$this->assertEquals('There is 1 action(s) to deploy'.PHP_EOL.'Deploy action 1'.PHP_EOL.'Done'.PHP_EOL, $commandTester->getDisplay());
}
}
50 changes: 50 additions & 0 deletions Tests/Units/Command/SpreadListCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Spy\TimelineBundle\Tests\Units\Command;

use PHPUnit\Framework\TestCase;
use Spy\TimelineBundle\Command\SpreadListCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;

class SpreadListCommandTest extends TestCase
{
public function testExecuteWithNoSpread()
{
$deployer = $this->createMock(\Spy\Timeline\Spread\Deployer::class);
$deployer->method('getSpreads')->willReturn([]);

$command = new SpreadListCommand($deployer);

$application = new Application();
$application->add($command);

$command = $application->find('spy_timeline:spreads');

$commandTester = new CommandTester($command);
$commandTester->execute(['command' => $command->getName()], []);

$this->assertEquals('There is 0 timeline spread(s) defined'.PHP_EOL, $commandTester->getDisplay());
}

public function testExecuteWithOneSpread()
{
// one spread
$spread = $this->createMock(\Spy\Timeline\Spread\SpreadInterface::class);

$deployer = $this->createMock(\Spy\Timeline\Spread\Deployer::class);
$deployer->method('getSpreads')->willReturn([$spread]);

$command = new SpreadListCommand($deployer);

$application = new Application();
$application->add($command);

$command = $application->find('spy_timeline:spreads');

$commandTester = new CommandTester($command);
$commandTester->execute(['command' => $command->getName()]);

$this->assertEquals('There is 1 timeline spread(s) defined'.PHP_EOL.'- '.get_class($spread).PHP_EOL, $commandTester->getDisplay());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Spy\TimelineBundle\Tests\Units\DependencyInjection\Compiler;

use PHPUnit\Framework\TestCase;
use Spy\TimelineBundle\DependencyInjection\Compiler\AddLocatorCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

class AddLocatorCompilerPassTest extends TestCase
{
public function testProcess()
{
//there are 4 (3 unique) config locator services so there should be only 3 addLocator calls
$configLocators = ['foo.service', 'bar.service'];
$taggedServicesResult = ['baz.service' => [], 'foo.service' => []];

//setup mocks
$definition = $this->createMock(Definition::class);
$definition
->expects($this->exactly(3))
->method('addMethodCall')
->with('addLocator', [$definition])
->willReturn($definition);

$containerBuilder = $this->createMock(ContainerBuilder::class);
$containerBuilder
->expects($this->exactly(1))
->method('findTaggedServiceIds')
->with('spy_timeline.filter.data_hydrator.locator')
->willReturn($taggedServicesResult);

$containerBuilder->method('hasParameter')->willReturnCallback(function ($argument) {
switch ($argument) {
case "spy_timeline.filter.data_hydrator.locators_config":
return true;
}
});

$matcherGetParameter = $this->exactly(1);
$containerBuilder
->expects($matcherGetParameter)
->method('getParameter')
->willReturnCallback(function ($value) use ($matcherGetParameter, $configLocators) {
match ($matcherGetParameter->getInvocationCount()) {
1 => $this->assertEquals('spy_timeline.filter.data_hydrator.locators_config', $value),
};

return $configLocators;
});


$matcherGetDefinition = $this->exactly(5);
$containerBuilder
->expects($matcherGetDefinition)
->method('getDefinition')
->willReturnCallback(function (string $value) use ($matcherGetDefinition, $definition) {
match ($matcherGetDefinition->getInvocationCount()) {
1, 4 => $this->assertEquals('foo.service', $value),
2 => $this->assertEquals('bar.service', $value),
3 => $this->assertEquals('baz.service', $value),
5 => $this->assertEquals('spy_timeline.filter.data_hydrator', $value),
};

return $definition;
});


$compiler = new AddLocatorCompilerPass();
$compiler->process($containerBuilder);
}
}
Loading
Loading