Skip to content

Commit

Permalink
Fix tests to accommodate internal_tag option
Browse files Browse the repository at this point in the history
- fix construction of NikicPhpParser to include the new $config param
- fix assertions of config handling to account for the new option
  • Loading branch information
brightbyte committed Dec 14, 2023
1 parent 524582e commit c905ffd
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(
$this->dependencyResolvers = $dependencyResolvers;
$this->currentReference = $fileReferenceBuilder;

$this->internalTag = $config['internal_tag'] ?: null;
$this->internalTag = $config['internal_tag'] ?? null;
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/Core/Ast/AstMapFlattenGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected function setUp(): void
(new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer()),
new AstFileReferenceInMemoryCache(),
new TypeResolver(),
[],
[]
),
$this->eventDispatcher
Expand Down
3 changes: 2 additions & 1 deletion tests/Core/Ast/AstMapGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ private function getAstMap(string $fixture): AstMap
new AnonymousClassExtractor(),
new ClassConstantExtractor(),
new KeywordExtractor($typeResolver),
]
],
[]
),
new EventDispatcher()
);
Expand Down
3 changes: 2 additions & 1 deletion tests/Core/Ast/Parser/AnnotationReferenceExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public function testPropertyDependencyResolving(): void
[
new AnnotationReferenceExtractor($typeResolver),
new KeywordExtractor($typeResolver),
]
],
[]
);

$filePath = __DIR__.'/Fixtures/AnnotationDependency.php';
Expand Down
3 changes: 2 additions & 1 deletion tests/Core/Ast/Parser/AnonymousClassExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public function testPropertyDependencyResolving(): void
new TypeResolver(),
[
new AnonymousClassExtractor(),
]
],
[]
);

$filePath = __DIR__.'/Fixtures/AnonymousClass.php';
Expand Down
3 changes: 2 additions & 1 deletion tests/Core/Ast/Parser/ClassConstantExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public function testPropertyDependencyResolving(): void
new TypeResolver(),
[
new ClassConstantExtractor(),
]
],
[]
);

$filePath = __DIR__.'/Fixtures/ClassConst.php';
Expand Down
3 changes: 2 additions & 1 deletion tests/Core/Ast/Parser/ClassDocBlockExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function testMethodResolving(): void
$typeResolver,
[
new KeywordExtractor($typeResolver),
]
],
[]
);

$filePath = __DIR__.'/Fixtures/ClassDocBlockDependency.php';
Expand Down
6 changes: 5 additions & 1 deletion tests/Core/Ast/Parser/NikicPhpParser/NikicPhpParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function setUp(): void
$this->createMock(Parser::class),
new AstFileReferenceInMemoryCache(),
$this->createMock(TypeResolver::class),
[],
[]
);
}
Expand All @@ -42,6 +43,7 @@ public function testParseDoesNotIgnoreUsesByDefault(): void
(new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer()),
new AstFileReferenceInMemoryCache(),
$typeResolver,
[],
[]
);

Expand All @@ -59,6 +61,7 @@ public function testParseAttributes(): void
(new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer()),
new AstFileReferenceInMemoryCache(),
$typeResolver,
[],
[]
);

Expand All @@ -77,7 +80,8 @@ public function testParseTemplateTypes(): void
(new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer()),
new AstFileReferenceInMemoryCache(),
$typeResolver,
[new AnnotationReferenceExtractor($typeResolver)]
[new AnnotationReferenceExtractor($typeResolver)],
[]
);

$filePath = __DIR__.'/Fixtures/TemplateTypes.php';
Expand Down
3 changes: 2 additions & 1 deletion tests/Core/Dependency/Emitter/EmitterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function getEmittedDependencies(DependencyEmitterInterface $emitter, $fil
new StaticExtractor($typeResolver),
new FunctionCallResolver($typeResolver),
new VariableExtractor(),
]
],
[]
);
$astMap = (new AstLoader($parser, new EventDispatcher()))->createAstMap($files);
$result = new DependencyList();
Expand Down
44 changes: 29 additions & 15 deletions tests/Supportive/DependencyInjection/DeptracExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ final class DeptracExtensionTest extends TestCase
],
];

private array $analyserDefaults = [
'internal_tag' => '@internal',
'types' => [
'class',
'function'
],
];

protected function setUp(): void
{
parent::setUp();
Expand All @@ -52,7 +60,7 @@ public function testDefaults(): void
self::assertSame([], $this->container->getParameter('ruleset'));
self::assertSame([], $this->container->getParameter('skip_violations'));
self::assertSame($this->formatterDefaults, $this->container->getParameter('formatters'));
self::assertSame(['types' => [EmitterType::CLASS_TOKEN->value, EmitterType::FUNCTION_TOKEN->value]], $this->container->getParameter('analyser'));
self::assertSame($this->analyserDefaults, $this->container->getParameter('analyser'));
self::assertSame(true, $this->container->getParameter('ignore_uncovered_internal_classes'));
}

Expand All @@ -70,7 +78,7 @@ public function testDefaultsWithEmptyRoot(): void
self::assertSame([], $this->container->getParameter('ruleset'));
self::assertSame([], $this->container->getParameter('skip_violations'));
self::assertSame($this->formatterDefaults, $this->container->getParameter('formatters'));
self::assertSame(['types' => [EmitterType::CLASS_TOKEN->value, EmitterType::FUNCTION_TOKEN->value]], $this->container->getParameter('analyser'));
self::assertSame($this->analyserDefaults, $this->container->getParameter('analyser'));
self::assertSame(true, $this->container->getParameter('ignore_uncovered_internal_classes'));
}

Expand Down Expand Up @@ -307,10 +315,12 @@ public function testNullAnalyser(): void
],
];

$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('The child config "types" under "deptrac.analyser" must be configured.');

$this->extension->load($configs, $this->container);

self::assertSame(
$this->analyserDefaults,
$this->container->getParameter('analyser')
);
}

public function testEmptyAnalyser(): void
Expand All @@ -321,10 +331,12 @@ public function testEmptyAnalyser(): void
],
];

$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('The child config "types" under "deptrac.analyser" must be configured.');

$this->extension->load($configs, $this->container);

self::assertSame(
$this->analyserDefaults,
$this->container->getParameter('analyser')
);
}

public function testInvalidAnalyserTypes(): void
Expand All @@ -333,7 +345,7 @@ public function testInvalidAnalyserTypes(): void
'deptrac' => [
'analyser' => [
'types' => ['invalid'],
],
] + $this->analyserDefaults,
],
];

Expand All @@ -349,14 +361,14 @@ public function testNullAnalyserTypes(): void
'deptrac' => [
'analyser' => [
'types' => null,
],
] + $this->analyserDefaults,
],
];

$this->extension->load($configs, $this->container);

self::assertSame(
['types' => []],
['types' => []] + $this->analyserDefaults,
$this->container->getParameter('analyser')
);
}
Expand All @@ -367,14 +379,14 @@ public function testEmptyAnalyserTypes(): void
'deptrac' => [
'analyser' => [
'types' => [],
],
] + $this->analyserDefaults,
],
];

$this->extension->load($configs, $this->container);

self::assertSame(
['types' => []],
['types' => []] + $this->analyserDefaults,
$this->container->getParameter('analyser')
);
}
Expand All @@ -385,14 +397,15 @@ public function testAnalyserWithDuplicateTypes(): void
'deptrac' => [
'analyser' => [
'types' => [EmitterType::CLASS_TOKEN->value, EmitterType::CLASS_TOKEN->value],
],
] + $this->analyserDefaults,
],
];

$this->extension->load($configs, $this->container);

self::assertSame(
['types' => [EmitterType::CLASS_TOKEN->value, EmitterType::CLASS_TOKEN->value]],
['types' => [EmitterType::CLASS_TOKEN->value, EmitterType::CLASS_TOKEN->value]]
+ $this->analyserDefaults,
$this->container->getParameter('analyser')
);
}
Expand Down Expand Up @@ -527,4 +540,5 @@ public function testCodeclimateFormatterRequiresValidSeverity(): void

$this->extension->load($configs, $this->container);
}

}

0 comments on commit c905ffd

Please sign in to comment.