Skip to content

Commit

Permalink
[TEST] Fixed phpstan findings
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Jul 30, 2019
1 parent 596e698 commit 19d99dd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 24 deletions.
5 changes: 5 additions & 0 deletions phpstan.neon
Expand Up @@ -9,4 +9,9 @@ parameters:
# Symfony DI
- '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::fixXmlConfig\(\).#'
- '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::addDefaultsIfNotSet\(\).#'
- '/Call to method getException\(\) on an unknown class Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent./'

# PHPUnit
-
message: '#Property .*::\$.* has no typehint specified.#'
path: tests/
13 changes: 3 additions & 10 deletions src/DependencyInjection/Configuration.php
Expand Up @@ -24,11 +24,8 @@ public function getConfigTreeBuilder()
$treeBuilder = new TreeBuilder('core23_menu');

// Keep compatibility with symfony/config < 4.2
if (!method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->root('core23_menu');
} else {
$rootNode = $treeBuilder->getRootNode();
}
$rootNode = method_exists(TreeBuilder::class, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('core23_menu');

\assert($rootNode instanceof ArrayNodeDefinition);

$this->addMenuSection($rootNode);
Expand Down Expand Up @@ -112,11 +109,7 @@ private function getPathNode(string $name = ''): NodeInterface
$treeBuilder = new TreeBuilder($name);

// Keep compatibility with symfony/config < 4.2
if (!method_exists($treeBuilder, 'getRootNode')) {
$definition = $treeBuilder->root($name);
} else {
$definition = $treeBuilder->getRootNode();
}
$definition = method_exists(TreeBuilder::class, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root($name);
\assert($definition instanceof ArrayNodeDefinition);

$this->buildPathNode($definition);
Expand Down
5 changes: 3 additions & 2 deletions tests/Core23MenuBundleTest.php
Expand Up @@ -11,16 +11,17 @@

use Core23\MenuBundle\Core23MenuBundle;
use Core23\MenuBundle\DependencyInjection\Compiler\MenuCompilerPass;
use Core23\MenuBundle\DependencyInjection\Core23MenuExtension;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;

final class Core23MenuBundleTest extends TestCase
{
public function testItIsInstantiable(): void
public function testGetContainerExtension(): void
{
$bundle = new Core23MenuBundle();

static::assertInstanceOf(Core23MenuBundle::class, $bundle);
static::assertInstanceOf(Core23MenuExtension::class, $bundle->getContainerExtension());
}

public function testBuild(): void
Expand Down
8 changes: 7 additions & 1 deletion tests/DependencyInjection/Compiler/MenuCompilerPassTest.php
Expand Up @@ -11,6 +11,7 @@

use Core23\MenuBundle\DependencyInjection\Compiler\MenuCompilerPass;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

Expand All @@ -21,9 +22,14 @@ final class MenuCompilerPassTest extends TestCase
*/
private $container;

private $registryDefinitionMock;

protected function setUp(): void
{
$this->registryDefinitionMock = $this->prophesize(Definition::class);

$this->container = new ContainerBuilder();
$this->container->setDefinition('sonata.block.menu.registry', $this->registryDefinitionMock->reveal());
}

public function testProcess(): void
Expand Down Expand Up @@ -56,6 +62,6 @@ public function testProcessWithEmptyGroups(): void
$compiler = new MenuCompilerPass();
$compiler->process($this->container);

static::assertTrue(true);
$this->registryDefinitionMock->addMethodCall(Argument::any())->shouldNotHaveBeenCalled();
}
}
11 changes: 0 additions & 11 deletions tests/Menu/ConfigBuilderTest.php
Expand Up @@ -10,7 +10,6 @@
namespace Core23\MenuBundle\Tests\Menu;

use Core23\MenuBundle\Menu\ConfigBuilder;
use Core23\MenuBundle\Menu\ConfigBuilderInterface;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use PHPUnit\Framework\TestCase;
Expand All @@ -28,16 +27,6 @@ protected function setUp(): void
$this->translator = $this->prophesize(TranslatorInterface::class);
}

public function testItIsInstantiable(): void
{
$builder = new ConfigBuilder(
$this->factory->reveal(),
$this->translator->reveal()
);

static::assertInstanceOf(ConfigBuilderInterface::class, $builder);
}

public function testBuildMenuWithoutItems(): void
{
$builder = new ConfigBuilder(
Expand Down

0 comments on commit 19d99dd

Please sign in to comment.