diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..34b56ec --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,45 @@ +name: run-tests + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest] + php: [8.1] + stability: [prefer-lowest, prefer-stable] + + name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, json + coverage: none + + - name: Install plantuml & graphviz + run: sudo apt-get install -y plantuml graphviz + + - name: Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Install dependencies + run: | + composer update --${{ matrix.stability }} --prefer-dist --no-interaction + + - name: Execute tests + run: make test diff --git a/.travis.yml b/.travis.yml index 84851bb..2aa6d18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,7 @@ os: dist: "bionic" php: - - "7.4" - - "7.3" - - "7.2" + - "8.1" install: - "mkdir -p build/logs" diff --git a/Dockerfile b/Dockerfile index 476b411..dd96609 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM php:7.3-cli +FROM php:8.1-cli RUN mkdir -p /usr/share/man/man1 \ && apt-get update && apt-get install -y \ default-jdk \ @@ -7,8 +7,11 @@ RUN mkdir -p /usr/share/man/man1 \ && apt-get install -y \ graphviz \ plantuml + COPY . /dephpend WORKDIR /dephpend + RUN curl https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer | php -- --quiet \ && php -n composer.phar install -ENTRYPOINT [ "php", "-n", "-d memory_limit=-1", "./bin/dephpend" ] + +ENTRYPOINT [ "php", "-n", "-d", "memory_limit=-1", "./bin/dephpend" ] diff --git a/Makefile b/Makefile index 083ca58..9cec68a 100644 --- a/Makefile +++ b/Makefile @@ -44,8 +44,8 @@ cov: s: style style: - @$(PHP_NO_INI) vendor/bin/php-cs-fixer fix --level=psr2 --verbose src - @$(PHP_NO_INI) vendor/bin/php-cs-fixer fix --level=psr2 --verbose tests + @$(PHP_NO_INI) vendor/bin/php-cs-fixer fix --rules=@PSR12 --verbose src + @$(PHP_NO_INI) vendor/bin/php-cs-fixer fix --rules=@PSR12 --verbose tests phar: @php composer.phar update --no-dev diff --git a/composer.json b/composer.json index 86228f0..131b5e9 100644 --- a/composer.json +++ b/composer.json @@ -10,10 +10,10 @@ "homepage": "https://dephpend.com", "bin": ["bin/dephpend", "bin/php-trace"], "require": { - "php": "^7.2", + "php": "^8.1", "nikic/php-parser": "^4.0", - "symfony/console": "^4 || ^5", - "symfony/event-dispatcher": "^4 || ^5" + "symfony/console": "^6", + "symfony/event-dispatcher": "^6" }, "suggest": { "ext-json": "*", @@ -21,10 +21,10 @@ "ext-tokenizer": "*" }, "require-dev": { - "mikey179/vfsstream": "^1.6", - "phpunit/phpunit": "^8.0", - "squizlabs/php_codesniffer": "^3.3", - "friendsofphp/php-cs-fixer": "^2.12" + "mikey179/vfsstream": "^1.6.11", + "phpunit/phpunit": "^9.5.24", + "squizlabs/php_codesniffer": "^3.7", + "friendsofphp/php-cs-fixer": "^3.11" }, "minimum-stability": "stable", "prefer-stable": true, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ced3748..96a196d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -4,7 +4,6 @@ beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" beStrictAboutTodoAnnotatedTests="true" - forceCoversAnnotation="true" colors="true" verbose="true"> diff --git a/src/Analyser/DependencyInspectionVisitor.php b/src/Analyser/DependencyInspectionVisitor.php index f6b50b0..fd67b8f 100644 --- a/src/Analyser/DependencyInspectionVisitor.php +++ b/src/Analyser/DependencyInspectionVisitor.php @@ -153,7 +153,7 @@ public function beforeTraverse(array $nodes) /** * @return DependencyMap */ - public function dependencies() : DependencyMap + public function dependencies(): DependencyMap { return $this->dependencies; } @@ -173,6 +173,9 @@ private function setCurrentClass(ClassLikeNode $node) } elseif ($node instanceof TraitNode) { // @codeCoverageIgnoreEnd $this->currentClass = $this->dependencyFactory->createTraitFromStringArray($node->namespacedName->parts); + } elseif ($node instanceof Node\Stmt\Enum_) { + // @codeCoverageIgnoreEnd + $this->currentClass = $this->dependencyFactory->createEnumFromStringArray($node->namespacedName->parts); } else { $this->currentClass = $node->isAbstract() ? $this->dependencyFactory->createAbstractClazzFromStringArray($node->namespacedName->parts) diff --git a/src/Analyser/Metrics.php b/src/Analyser/Metrics.php index 332649e..81e5060 100644 --- a/src/Analyser/Metrics.php +++ b/src/Analyser/Metrics.php @@ -18,7 +18,7 @@ class Metrics * * @return float Value from 0 (completely concrete) to 1 (completely abstract) */ - public function abstractness(DependencyMap $map) : float + public function abstractness(DependencyMap $map): float { $abstractions = $this->abstractClassCount($map) + $this->interfaceCount($map) @@ -30,28 +30,28 @@ public function abstractness(DependencyMap $map) : float return $abstractions / $allClasses; } - public function classCount(DependencyMap $map) : int + public function classCount(DependencyMap $map): int { return $this->countFilteredItems($map, function (Dependency $dependency) { return $dependency instanceof Clazz; }); } - public function abstractClassCount(DependencyMap $map) : int + public function abstractClassCount(DependencyMap $map): int { return $this->countFilteredItems($map, function (Dependency $dependency) { return $dependency instanceof AbstractClazz; }); } - public function interfaceCount(DependencyMap $map) : int + public function interfaceCount(DependencyMap $map): int { return $this->countFilteredItems($map, function (Dependency $dependency) { return $dependency instanceof Interfaze; }); } - public function traitCount(DependencyMap $map) : int + public function traitCount(DependencyMap $map): int { return $this->countFilteredItems($map, function (Dependency $dependency) { return $dependency instanceof Trait_; @@ -65,7 +65,7 @@ public function traitCount(DependencyMap $map) : int * * @return array */ - public function afferentCoupling(DependencyMap $map) : array + public function afferentCoupling(DependencyMap $map): array { return $map->fromDependencies()->reduce([], function (array $afferent, Dependency $from) use ($map) { $afferent[$from->toString()] = $map->reduce( @@ -87,7 +87,7 @@ function (int $count, Dependency $fromOther, Dependency $to) use ($from): int { * * @return array */ - public function efferentCoupling(DependencyMap $map) : array + public function efferentCoupling(DependencyMap $map): array { return $map->reduce([], function (array $efferent, Dependency $from, Dependency $to) use ($map) { $efferent[$from->toString()] = $map->get($from)->count(); @@ -102,7 +102,7 @@ public function efferentCoupling(DependencyMap $map) : array * * @return array Key: Class Value: Range from 0 (completely stable) to 1 (completely unstable) */ - public function instability(DependencyMap $map) : array + public function instability(DependencyMap $map): array { $ce = $this->efferentCoupling($map); $ca = $this->afferentCoupling($map); diff --git a/src/Analyser/Parser.php b/src/Analyser/Parser.php index 36c2a71..a2da813 100644 --- a/src/Analyser/Parser.php +++ b/src/Analyser/Parser.php @@ -1,8 +1,10 @@ -parser = $parser; } - public function analyse(PhpFileSet $files) : DependencyMap + public function analyse(PhpFileSet $files): DependencyMap { $files->each(function (PhpFile $file) { try { diff --git a/src/Analyser/XDebugFunctionTraceAnalyser.php b/src/Analyser/XDebugFunctionTraceAnalyser.php index d00e98b..19fa54d 100644 --- a/src/Analyser/XDebugFunctionTraceAnalyser.php +++ b/src/Analyser/XDebugFunctionTraceAnalyser.php @@ -14,8 +14,8 @@ */ class XDebugFunctionTraceAnalyser { - const PARAMETER_START_INDEX = 11; - const FUNCTION_NAME_INDEX = 5; + public const PARAMETER_START_INDEX = 11; + public const FUNCTION_NAME_INDEX = 5; /** @var DependencyFactory */ private $dependencyFactory; @@ -28,9 +28,9 @@ public function __construct(DependencyFactory $dependencyFactory) $this->dependencyFactory = $dependencyFactory; } - public function analyse(\SplFileInfo $file) : DependencyMap + public function analyse(\SplFileInfo $file): DependencyMap { - $fileHandle = @fopen($file->getPathname(), 'r'); + $fileHandle = !empty($file->getPathname()) ? @fopen($file->getPathname(), 'r') : false; if (!$fileHandle) { throw new \InvalidArgumentException('Unable to open trace file for reading'); } @@ -45,7 +45,7 @@ public function analyse(\SplFileInfo $file) : DependencyMap return $dependencies; } - private function extractDependenciesFromLine(DependencyMap $dependencies, string $line) : DependencyMap + private function extractDependenciesFromLine(DependencyMap $dependencies, string $line): DependencyMap { $tokens = $this->extractFields($line); if ($this->isNotMethodEntryTrace($tokens) @@ -59,35 +59,35 @@ private function extractDependenciesFromLine(DependencyMap $dependencies, string ); } - private function isNotMethodEntryTrace(array $tokens) : bool + private function isNotMethodEntryTrace(array $tokens): bool { return count($tokens) <= self::PARAMETER_START_INDEX; } - private function extractFields(string $line) : array + private function extractFields(string $line): array { return explode("\t", str_replace("\n", '', $line)); } - private function containsOnlyScalarValues(array $tokens) : bool + private function containsOnlyScalarValues(array $tokens): bool { return strpos(implode('', array_slice($tokens, self::PARAMETER_START_INDEX)), 'class ') === false; } - private function isGlobalFunction(array $tokens) : bool + private function isGlobalFunction(array $tokens): bool { return strpos($tokens[self::FUNCTION_NAME_INDEX], '->') === false && strpos($tokens[self::FUNCTION_NAME_INDEX], '::') === false; } - private function extractFromClass(array $tokens) : Clazz + private function extractFromClass(array $tokens): Clazz { $classWithoutMethod = preg_split('/(->)|(::)/', $tokens[self::FUNCTION_NAME_INDEX]); $classParts = explode("\\", $classWithoutMethod[0]); return $this->dependencyFactory->createClazzFromStringArray($classParts); } - private function extractToSet(array $tokens) : DependencySet + private function extractToSet(array $tokens): DependencySet { return array_reduce(array_slice($tokens, self::PARAMETER_START_INDEX), function (DependencySet $set, string $token) { if (strpos($token, 'class') === false) { diff --git a/src/Cli/Application.php b/src/Cli/Application.php index 29a66e4..99cf740 100644 --- a/src/Cli/Application.php +++ b/src/Cli/Application.php @@ -12,7 +12,7 @@ class Application extends \Symfony\Component\Console\Application { - const XDEBUG_WARNING = 'You are running dePHPend with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug'; + public const XDEBUG_WARNING = 'You are running dePHPend with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug'; /** @var ErrorOutput */ private $errorOutput; diff --git a/src/Cli/ErrorOutput.php b/src/Cli/ErrorOutput.php index d5ba62c..b612a51 100644 --- a/src/Cli/ErrorOutput.php +++ b/src/Cli/ErrorOutput.php @@ -20,4 +20,4 @@ public function writeln(string $message): void { $this->symfonyStyle->getErrorStyle()->writeln($message); } -} \ No newline at end of file +} diff --git a/src/Cli/MetricsCommand.php b/src/Cli/MetricsCommand.php index fbdf38e..d52ffdc 100644 --- a/src/Cli/MetricsCommand.php +++ b/src/Cli/MetricsCommand.php @@ -58,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output) return 0; } - private function combineMetrics(array $afferentCoupling, array $efferentCoupling, array $instability) : array + private function combineMetrics(array $afferentCoupling, array $efferentCoupling, array $instability): array { $result = []; foreach ($afferentCoupling as $className => $afferentCouplingValue) { diff --git a/src/Cli/TestFeaturesCommand.php b/src/Cli/TestFeaturesCommand.php index 6235ab3..6c388cb 100644 --- a/src/Cli/TestFeaturesCommand.php +++ b/src/Cli/TestFeaturesCommand.php @@ -46,7 +46,7 @@ protected function execute(InputInterface $input, OutputInterface $output) return 0; } - public function runTest(string $filename) : array + public function runTest(string $filename): array { $_SERVER['argv'] = [0, 'text', $filename]; $application = new Application('', '', (new DependencyContainer([]))->dispatcher()); @@ -61,7 +61,7 @@ public function runTest(string $filename) : array : [false, '[✗] '.$this->extractFeatureName($filename).'']; } - private function cleanOutput(string $output) : string + private function cleanOutput(string $output): string { return trim(str_replace(Application::XDEBUG_WARNING, '', $output)); } @@ -71,7 +71,7 @@ private function cleanOutput(string $output) : string * * @return string */ - private function extractFeatureName(string $filename) : string + private function extractFeatureName(string $filename): string { preg_match_all('/((?:^|[A-Z])[a-z0-9]+)/', $filename, $matches); return str_replace(['cli', ' feature'], '', strtolower(implode(' ', $matches[1]))); @@ -82,7 +82,7 @@ private function extractFeatureName(string $filename) : string * * @return string */ - private function getExpectations(string $filename) : string + private function getExpectations(string $filename): string { $expectations = []; foreach (file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) { @@ -98,7 +98,7 @@ private function getExpectations(string $filename) : string * * @return \RegexIterator */ - protected function fetchAllFeatureTests() : \RegexIterator + protected function fetchAllFeatureTests(): \RegexIterator { return new \RegexIterator( new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__ . '/../../tests/samples')), @@ -112,14 +112,14 @@ protected function fetchAllFeatureTests() : \RegexIterator * * @return array */ - protected function runAllTests($files) : array + protected function runAllTests($files): array { return array_map(function ($filename) { return $this->runTest($filename[0]); }, iterator_to_array($files)); } - private function sortSuccessFirst() : \Closure + private function sortSuccessFirst(): \Closure { return function (array $x, array $y) { if ($x[0] === true) { diff --git a/src/Dependencies/ClazzLike.php b/src/Dependencies/ClazzLike.php index bf83b93..0c8ea89 100644 --- a/src/Dependencies/ClazzLike.php +++ b/src/Dependencies/ClazzLike.php @@ -27,46 +27,46 @@ public function __construct(string $name, Namespaze $clazzNamespace = null) $this->namespaze = $clazzNamespace; } - public function equals(Dependency $other) : bool + public function equals(Dependency $other): bool { return $this->toString() === $other->toString(); } - public function toString() : string + public function toString(): string { return $this->hasNamespace() ? $this->namespaze.'\\'.$this->name : $this->name; } - public function __toString() : string + public function __toString(): string { return $this->toString(); } - public function namespaze() : Namespaze + public function namespaze(): Namespaze { return $this->namespaze; } - public function hasNamespace() : bool + public function hasNamespace(): bool { return $this->namespaze->toString() !== ''; } - public function count() : int + public function count(): int { return 1 + $this->namespaze->count(); } - public function reduceToDepth(int $maxDepth) : Dependency + public function reduceToDepth(int $maxDepth): Dependency { return $this->count() <= $maxDepth || $maxDepth === 0 ? $this : $this->namespaze->reduceToDepth($maxDepth); } - public function reduceDepthFromLeftBy(int $reduction) : Dependency + public function reduceDepthFromLeftBy(int $reduction): Dependency { return $this->count() <= $reduction || $reduction === 0 ? $this @@ -85,12 +85,12 @@ private function ensureClassNameIsValid(string $name) } } - public function inNamespaze(Namespaze $other) : bool + public function inNamespaze(Namespaze $other): bool { return $this->namespaze->inNamespaze($other); } - public function isNamespaced() : bool + public function isNamespaced(): bool { return $this->namespaze->count() > 0; } diff --git a/src/Dependencies/Dependency.php b/src/Dependencies/Dependency.php index 4dba315..1305025 100644 --- a/src/Dependencies/Dependency.php +++ b/src/Dependencies/Dependency.php @@ -6,19 +6,19 @@ interface Dependency extends \Countable { - public function reduceToDepth(int $maxDepth) : Dependency; + public function reduceToDepth(int $maxDepth): Dependency; - public function reduceDepthFromLeftBy(int $reduction) : Dependency; + public function reduceDepthFromLeftBy(int $reduction): Dependency; - public function equals(Dependency $other) : bool; + public function equals(Dependency $other): bool; - public function toString() : string; + public function toString(): string; - public function __toString() : string; + public function __toString(): string; - public function namespaze() : Namespaze; + public function namespaze(): Namespaze; - public function isNamespaced() : bool; + public function isNamespaced(): bool; - public function inNamespaze(Namespaze $other) : bool; + public function inNamespaze(Namespaze $other): bool; } diff --git a/src/Dependencies/DependencyFactory.php b/src/Dependencies/DependencyFactory.php index f925ad6..56597f3 100644 --- a/src/Dependencies/DependencyFactory.php +++ b/src/Dependencies/DependencyFactory.php @@ -11,7 +11,7 @@ class DependencyFactory * * @return Dependency */ - final public function createClazzFromStringArray(array $parts) : Dependency + final public function createClazzFromStringArray(array $parts): Dependency { try { $clazz = new Clazz( @@ -29,7 +29,7 @@ final public function createClazzFromStringArray(array $parts) : Dependency * * @return AbstractClazz */ - final public function createAbstractClazzFromStringArray(array $parts) : AbstractClazz + final public function createAbstractClazzFromStringArray(array $parts): AbstractClazz { return new AbstractClazz( $this->extractClazzPart($parts), @@ -42,7 +42,7 @@ final public function createAbstractClazzFromStringArray(array $parts) : Abstrac * * @return Interfaze */ - final public function createInterfazeFromStringArray(array $parts) : Interfaze + final public function createInterfazeFromStringArray(array $parts): Interfaze { return new Interfaze( $this->extractClazzPart($parts), @@ -55,7 +55,7 @@ final public function createInterfazeFromStringArray(array $parts) : Interfaze * * @return Trait_ */ - final public function createTraitFromStringArray(array $parts) : Trait_ + final public function createTraitFromStringArray(array $parts): Trait_ { return new Trait_( $this->extractClazzPart($parts), @@ -63,6 +63,19 @@ final public function createTraitFromStringArray(array $parts) : Trait_ ); } + /** + * @param array $parts + * + * @return Enum_ + */ + final public function createEnumFromStringArray(array $parts): Enum_ + { + return new Enum_( + $this->extractClazzPart($parts), + new Namespaze($this->extractNamespaceParts($parts)) + ); + } + /** * @param array $parts * diff --git a/src/Dependencies/DependencyFilter.php b/src/Dependencies/DependencyFilter.php index b9d2342..813c7d3 100644 --- a/src/Dependencies/DependencyFilter.php +++ b/src/Dependencies/DependencyFilter.php @@ -19,7 +19,7 @@ public function __construct(array $internals) $this->internals = $internals; } - public function filterByOptions(DependencyMap $dependencies, array $options) : DependencyMap + public function filterByOptions(DependencyMap $dependencies, array $options): DependencyMap { if (isset($options['underscore-namespaces']) && $options['underscore-namespaces'] === true) { $dependencies = $this->mapNamespaces($dependencies); @@ -45,7 +45,7 @@ public function filterByOptions(DependencyMap $dependencies, array $options) : D return $dependencies; } - public function postFiltersByOptions(array $options) : \Closure + public function postFiltersByOptions(array $options): \Closure { $filters = []; if ($options['depth'] > 0) { @@ -58,7 +58,7 @@ public function postFiltersByOptions(array $options) : \Closure return Functional::compose(...$filters); } - public function removeInternals(DependencyMap $dependencies) : DependencyMap + public function removeInternals(DependencyMap $dependencies): DependencyMap { return $dependencies->reduce(new DependencyMap(), function (DependencyMap $map, Dependency $from, Dependency $to) { return !in_array($to->toString(), $this->internals, true) @@ -67,13 +67,13 @@ public function removeInternals(DependencyMap $dependencies) : DependencyMap }); } - public function filterByNamespace(DependencyMap $dependencies, string $namespace) : DependencyMap + public function filterByNamespace(DependencyMap $dependencies, string $namespace): DependencyMap { $namespace = new Namespaze(array_filter(explode('\\', $namespace))); return $dependencies->reduce(new DependencyMap(), $this->filterNamespaceFn($namespace)); } - public function excludeByRegex(DependencyMap $dependencies, string $regex) : DependencyMap + public function excludeByRegex(DependencyMap $dependencies, string $regex): DependencyMap { return $dependencies->reduce(new DependencyMap(), function (DependencyMap $map, Dependency $from, Dependency $to) use ($regex) { return preg_match($regex, $from->toString()) === 1 || preg_match($regex, $to->toString()) === 1 @@ -82,7 +82,7 @@ public function excludeByRegex(DependencyMap $dependencies, string $regex) : Dep }); } - public function filterByFromNamespace(DependencyMap $dependencies, string $namespace) : DependencyMap + public function filterByFromNamespace(DependencyMap $dependencies, string $namespace): DependencyMap { $namespace = new Namespaze(array_filter(explode('\\', $namespace))); return $dependencies->reduce(new DependencyMap(), function (DependencyMap $map, Dependency $from, Dependency $to) use ($namespace) { @@ -92,16 +92,16 @@ public function filterByFromNamespace(DependencyMap $dependencies, string $names }); } - private function filterNamespaceFn(Namespaze $namespaze) : \Closure + private function filterNamespaceFn(Namespaze $namespaze): \Closure { - return function (DependencyMap $map, Dependency $from, Dependency $to) use ($namespaze) : DependencyMap { + return function (DependencyMap $map, Dependency $from, Dependency $to) use ($namespaze): DependencyMap { return $from->inNamespaze($namespaze) && $to->inNamespaze($namespaze) ? $map->add($from, $to) : $map; }; } - public function filterByDepth(DependencyMap $dependencies, int $depth) : DependencyMap + public function filterByDepth(DependencyMap $dependencies, int $depth): DependencyMap { if ($depth === 0) { return clone $dependencies; @@ -115,7 +115,7 @@ public function filterByDepth(DependencyMap $dependencies, int $depth) : Depende }); } - public function filterClasses(DependencyMap $dependencies) : DependencyMap + public function filterClasses(DependencyMap $dependencies): DependencyMap { return $dependencies->reduce(new DependencyMap(), function (DependencyMap $map, Dependency $from, Dependency $to) { if ($from->namespaze()->count() === 0 || $to->namespaze()->count() === 0) { @@ -125,21 +125,21 @@ public function filterClasses(DependencyMap $dependencies) : DependencyMap }); } - public function reduceDependencyToNamespace() : \Closure + public function reduceDependencyToNamespace(): \Closure { - return function (Dependency $dependency) : Dependency { + return function (Dependency $dependency): Dependency { return $dependency->namespaze(); }; } - public function reduceDependencyByDepth(int $depth) : \Closure + public function reduceDependencyByDepth(int $depth): \Closure { - return function (Dependency $dependency) use ($depth) : Dependency { + return function (Dependency $dependency) use ($depth): Dependency { return $dependency->reduceToDepth($depth); }; } - public function mapNamespaces(DependencyMap $dependencies) : DependencyMap + public function mapNamespaces(DependencyMap $dependencies): DependencyMap { return $dependencies->reduceEachDependency(function (Dependency $dependency) { if (strpos($dependency->toString(), '_') === false) { diff --git a/src/Dependencies/DependencyMap.php b/src/Dependencies/DependencyMap.php index f7070eb..45acaa6 100644 --- a/src/Dependencies/DependencyMap.php +++ b/src/Dependencies/DependencyMap.php @@ -14,7 +14,7 @@ class DependencyMap extends AbstractMap * * @return DependencyMap */ - public function add(Dependency $from, Dependency $to) : self + public function add(Dependency $from, Dependency $to): self { $clone = clone $this; if ($from->equals($to) @@ -35,14 +35,14 @@ public function add(Dependency $from, Dependency $to) : self return $clone; } - public function addMap(self $other) : self + public function addMap(self $other): self { return $this->reduce($other, function (DependencyMap $map, Dependency $from, Dependency $to) { return $map->add($from, $to); }); } - public function addSet(Dependency $from, DependencySet $toSet) : self + public function addSet(Dependency $from, DependencySet $toSet): self { $clone = $toSet->reduce($this, function (DependencyMap $map, Dependency $to) use ($from) { return $map->add($from, $to); @@ -50,19 +50,19 @@ public function addSet(Dependency $from, DependencySet $toSet) : self return $clone; } - public function get(Dependency $from) : DependencySet + public function get(Dependency $from): DependencySet { return $this->map[$from->toString()][self::$VALUE]; } - public function fromDependencies() : DependencySet + public function fromDependencies(): DependencySet { return $this->reduce(new DependencySet(), function (DependencySet $set, Dependency $from) { return $set->add($from); }); } - public function allDependencies() : DependencySet + public function allDependencies(): DependencySet { return $this->reduce(new DependencySet(), function (DependencySet $set, Dependency $from, Dependency $to) { return $set @@ -71,7 +71,7 @@ public function allDependencies() : DependencySet }); } - public function mapAllDependencies(\Closure $mappers) : DependencySet + public function mapAllDependencies(\Closure $mappers): DependencySet { return $this->reduce(new DependencySet(), function (DependencySet $set, Dependency $from, Dependency $to) use ($mappers) { return $set @@ -88,14 +88,14 @@ public function mapAllDependencies(\Closure $mappers) : DependencySet * * @return DependencyMap */ - public function reduceEachDependency(\Closure $mappers) : DependencyMap + public function reduceEachDependency(\Closure $mappers): DependencyMap { return $this->reduce(new self(), function (self $map, Dependency $from, Dependency $to) use ($mappers) { return $map->add($mappers($from), $mappers($to)); }); } - public function toString() : string + public function toString(): string { return trim($this->reduce('', function (string $carry, Dependency $key, Dependency $value) { return $carry.$key->toString().' --> '.$value->toString().PHP_EOL; diff --git a/src/Dependencies/DependencySet.php b/src/Dependencies/DependencySet.php index 53de71c..c706a5c 100644 --- a/src/Dependencies/DependencySet.php +++ b/src/Dependencies/DependencySet.php @@ -13,7 +13,7 @@ class DependencySet extends AbstractCollection * * @return DependencySet */ - public function add(Dependency $dependency) : DependencySet + public function add(Dependency $dependency): DependencySet { $clone = clone $this; if ($this->contains($dependency) diff --git a/src/Dependencies/Enum_.php b/src/Dependencies/Enum_.php new file mode 100644 index 0000000..f29a8f6 --- /dev/null +++ b/src/Dependencies/Enum_.php @@ -0,0 +1,9 @@ +parts); } - public function namespaze() : Namespaze + public function namespaze(): Namespaze { return $this; } @@ -45,12 +45,12 @@ public function namespaze() : Namespaze /** * @return string[] */ - public function parts() : array + public function parts(): array { return $this->parts; } - public function reduceToDepth(int $maxDepth) : Dependency + public function reduceToDepth(int $maxDepth): Dependency { if ($maxDepth === 0 || $this->count() === $maxDepth) { return $this; @@ -61,29 +61,29 @@ public function reduceToDepth(int $maxDepth) : Dependency : new self(array_slice($this->parts, 0, $maxDepth)); } - public function reduceDepthFromLeftBy(int $reduction) : Dependency + public function reduceDepthFromLeftBy(int $reduction): Dependency { return $reduction >= $this->count() ? new self([]) : new self(array_slice($this->parts, $reduction)); } - public function equals(Dependency $other) : bool + public function equals(Dependency $other): bool { return $this->toString() === $other->toString(); } - public function toString() : string + public function toString(): string { return implode('\\', $this->parts); } - public function __toString() : string + public function __toString(): string { return $this->toString(); } - public function inNamespaze(Namespaze $other) : bool + public function inNamespaze(Namespaze $other): bool { return $other->toString() !== '' && $this->toString() !== '' @@ -95,7 +95,7 @@ public function inNamespaze(Namespaze $other) : bool * * @return bool */ - private function arrayContainsNotOnlyStrings(array $parts):bool + private function arrayContainsNotOnlyStrings(array $parts): bool { return Util::array_once($parts, function ($value) { return !is_string($value); diff --git a/src/Dependencies/NullDependency.php b/src/Dependencies/NullDependency.php index cb27d5e..8323574 100644 --- a/src/Dependencies/NullDependency.php +++ b/src/Dependencies/NullDependency.php @@ -6,22 +6,22 @@ class NullDependency implements Dependency { - public function reduceToDepth(int $maxDepth) : Dependency + public function reduceToDepth(int $maxDepth): Dependency { return new NullDependency(); } - public function reduceDepthFromLeftBy(int $reduction) : Dependency + public function reduceDepthFromLeftBy(int $reduction): Dependency { return new NullDependency(); } - public function equals(Dependency $other) : bool + public function equals(Dependency $other): bool { return false; } - public function toString() : string + public function toString(): string { return ''; } @@ -29,22 +29,22 @@ public function toString() : string /** * @return string */ - public function __toString() : string + public function __toString(): string { return $this->toString(); } - public function namespaze() : Namespaze + public function namespaze(): Namespaze { return new Namespaze([]); } - public function inNamespaze(Namespaze $other) : bool + public function inNamespaze(Namespaze $other): bool { return false; } - public function count() + public function count(): int { return 0; } diff --git a/src/Exceptions/ParserException.php b/src/Exceptions/ParserException.php index ba1255c..ab5dcbf 100644 --- a/src/Exceptions/ParserException.php +++ b/src/Exceptions/ParserException.php @@ -9,4 +9,4 @@ public function __construct(string $message, string $file) $this->message = $message; $this->file = $file; } -} \ No newline at end of file +} diff --git a/src/Formatters/DependencyStructureMatrixBuilder.php b/src/Formatters/DependencyStructureMatrixBuilder.php index a4225b9..3eb7a0b 100644 --- a/src/Formatters/DependencyStructureMatrixBuilder.php +++ b/src/Formatters/DependencyStructureMatrixBuilder.php @@ -10,10 +10,10 @@ class DependencyStructureMatrixBuilder { - public function buildMatrix(DependencyMap $dependencies, \Closure $mappers) : array + public function buildMatrix(DependencyMap $dependencies, \Closure $mappers): array { $emptyDsm = $this->createEmptyDsm($dependencies->mapAllDependencies($mappers)); - return $dependencies->reduce($emptyDsm, function (array $dsm, Dependency $from, Dependency $to) use ($mappers) : array { + return $dependencies->reduce($emptyDsm, function (array $dsm, Dependency $from, Dependency $to) use ($mappers): array { $from = $mappers($from)->toString(); $to = $mappers($to)->toString(); $dsm[$to][$from] += 1; diff --git a/src/Formatters/DependencyStructureMatrixHtmlFormatter.php b/src/Formatters/DependencyStructureMatrixHtmlFormatter.php index 0f37afa..3ab413c 100644 --- a/src/Formatters/DependencyStructureMatrixHtmlFormatter.php +++ b/src/Formatters/DependencyStructureMatrixHtmlFormatter.php @@ -23,7 +23,7 @@ public function __construct(DependencyStructureMatrixBuilder $dependencyStructur /** * {@inheritdoc} */ - public function format(DependencyMap $all, \Closure $mappers = null) : string + public function format(DependencyMap $all, \Closure $mappers = null): string { return $this->buildHtmlTable( $this->dependencyStructureMatrixBuilder->buildMatrix($all, $mappers ?? Functional::id()) @@ -35,7 +35,7 @@ public function format(DependencyMap $all, \Closure $mappers = null) : string * * @return string */ - private function buildHtmlTable(array $dependencyArray) : string + private function buildHtmlTable(array $dependencyArray): string { return '' .$this->tableHead($dependencyArray) diff --git a/src/Formatters/DotFormatter.php b/src/Formatters/DotFormatter.php index c8ab960..e830256 100644 --- a/src/Formatters/DotFormatter.php +++ b/src/Formatters/DotFormatter.php @@ -10,7 +10,7 @@ class DotFormatter implements Formatter { - public function format(DependencyMap $map, \Closure $mappers = null) : string + public function format(DependencyMap $map, \Closure $mappers = null): string { return 'digraph generated_by_dePHPend {'.PHP_EOL .$map->reduceEachDependency($mappers ?? Functional::id())->reduce('', function (string $carry, Dependency $from, Dependency $to) { diff --git a/src/Formatters/Formatter.php b/src/Formatters/Formatter.php index 94a78f1..187a7fe 100644 --- a/src/Formatters/Formatter.php +++ b/src/Formatters/Formatter.php @@ -13,5 +13,5 @@ interface Formatter * * @return string */ - public function format(DependencyMap $map, \Closure $mappers = null) : string; + public function format(DependencyMap $map, \Closure $mappers = null): string; } diff --git a/src/Formatters/PlantUmlFormatter.php b/src/Formatters/PlantUmlFormatter.php index cece6c6..98b2417 100644 --- a/src/Formatters/PlantUmlFormatter.php +++ b/src/Formatters/PlantUmlFormatter.php @@ -15,7 +15,7 @@ class PlantUmlFormatter implements Formatter /** * {@inheritdoc} */ - public function format(DependencyMap $map, \Closure $mappers = null) : string + public function format(DependencyMap $map, \Closure $mappers = null): string { return '@startuml'.PHP_EOL .$this->plantUmlNamespaceDefinitions($map).PHP_EOL @@ -23,7 +23,7 @@ public function format(DependencyMap $map, \Closure $mappers = null) : string .'@enduml'; } - private function dependenciesInPlantUmlFormat(DependencyMap $map) : string + private function dependenciesInPlantUmlFormat(DependencyMap $map): string { return str_replace( ['-->', '\\'], @@ -32,7 +32,7 @@ private function dependenciesInPlantUmlFormat(DependencyMap $map) : string ); } - private function plantUmlNamespaceDefinitions(DependencyMap $map) : string + private function plantUmlNamespaceDefinitions(DependencyMap $map): string { $namespaces = $map->reduce(new DependencySet(), function (DependencySet $set, Dependency $from, Dependency $to) { return $set @@ -44,7 +44,7 @@ private function plantUmlNamespaceDefinitions(DependencyMap $map) : string ); } - private function buildNamespaceTree(DependencySet $namespaces) : array + private function buildNamespaceTree(DependencySet $namespaces): array { return $namespaces->reduce([], function (array $total, Namespaze $namespaze) { $currentLevel = &$total; @@ -58,9 +58,9 @@ private function buildNamespaceTree(DependencySet $namespaces) : array }); } - private function printNamespaceTree(array $buildNamespaceTree) : string + private function printNamespaceTree(array $buildNamespaceTree): string { - return Util::reduce($buildNamespaceTree, function (string $total, string $namespace, array $children) : string { + return Util::reduce($buildNamespaceTree, function (string $total, string $namespace, array $children): string { return $total.'namespace '.$namespace.' {'.PHP_EOL.$this->printNamespaceTree($children).'}'.PHP_EOL; }, ''); } diff --git a/src/OS/PhpFile.php b/src/OS/PhpFile.php index 1937138..f2a6f8e 100644 --- a/src/OS/PhpFile.php +++ b/src/OS/PhpFile.php @@ -19,7 +19,7 @@ public function __construct(\SplFileInfo $file) $this->file = $file; } - public function file() : \SplFileInfo + public function file(): \SplFileInfo { return $this->file; } @@ -34,7 +34,7 @@ public function code() return @file_get_contents($this->file->getPathname()); } - public function toString() : string + public function toString(): string { return (string) $this->file; } @@ -42,7 +42,7 @@ public function toString() : string /** * @return string */ - public function __toString() : string + public function __toString(): string { return $this->toString(); } diff --git a/src/OS/PhpFileFinder.php b/src/OS/PhpFileFinder.php index 91e4f51..5648023 100644 --- a/src/OS/PhpFileFinder.php +++ b/src/OS/PhpFileFinder.php @@ -6,14 +6,14 @@ class PhpFileFinder { - public function find(\SplFileInfo $file) : PhpFileSet + public function find(\SplFileInfo $file): PhpFileSet { return $file->isDir() ? $this->findInDir($file) : (new PhpFileSet())->add(new PhpFile($file)); } - private function findInDir(\SplFileInfo $dir) : PhpFileSet + private function findInDir(\SplFileInfo $dir): PhpFileSet { $collection = new PhpFileSet(); $regexIterator = new \RegexIterator( @@ -35,7 +35,7 @@ private function findInDir(\SplFileInfo $dir) : PhpFileSet * * @return PhpFileSet */ - public function getAllPhpFilesFromSources(array $sources) : PhpFileSet + public function getAllPhpFilesFromSources(array $sources): PhpFileSet { return array_reduce( $sources, diff --git a/src/OS/PhpFileSet.php b/src/OS/PhpFileSet.php index 655804f..f872550 100644 --- a/src/OS/PhpFileSet.php +++ b/src/OS/PhpFileSet.php @@ -8,7 +8,7 @@ class PhpFileSet extends AbstractCollection { - public function add(PhpFile $file) : PhpFileSet + public function add(PhpFile $file): PhpFileSet { $clone = clone $this; if ($this->contains($file)) { @@ -19,14 +19,14 @@ public function add(PhpFile $file) : PhpFileSet return $clone; } - public function addAll(PhpFileSet $otherCollection) : PhpFileSet + public function addAll(PhpFileSet $otherCollection): PhpFileSet { return $otherCollection->reduce(clone $this, function (self $set, PhpFile $file) { return $set->add($file); }); } - public function contains($other) : bool + public function contains($other): bool { return $this->any(function (PhpFile $file) use ($other) { return $file->equals($other); diff --git a/src/OS/ShellWrapper.php b/src/OS/ShellWrapper.php index d28fc1b..6f70b82 100644 --- a/src/OS/ShellWrapper.php +++ b/src/OS/ShellWrapper.php @@ -15,7 +15,7 @@ class ShellWrapper * * @return int return var */ - public function run(string $command) : int + public function run(string $command): int { $output = []; $returnVar = 1; diff --git a/src/Util/AbstractCollection.php b/src/Util/AbstractCollection.php index dfbc64e..3776a85 100644 --- a/src/Util/AbstractCollection.php +++ b/src/Util/AbstractCollection.php @@ -12,7 +12,7 @@ abstract class AbstractCollection implements Collection /** * {@inheritdoc} */ - public function any(\Closure $closure) : bool + public function any(\Closure $closure): bool { foreach ($this->collection as $item) { if ($closure($item) === true) { @@ -28,7 +28,7 @@ public function any(\Closure $closure) : bool * * @return bool */ - public function none(\Closure $closure) : bool + public function none(\Closure $closure): bool { return !$this->any($closure); } @@ -46,7 +46,7 @@ public function each(\Closure $closure) /** * {@inheritdoc} */ - public function mapToArray(\Closure $closure) : array + public function mapToArray(\Closure $closure): array { return array_map($closure, $this->collection); } @@ -62,7 +62,7 @@ public function reduce($initial, \Closure $closure) /** * {@inheritdoc} */ - public function filter(\Closure $closure) : Collection + public function filter(\Closure $closure): Collection { $clone = clone $this; $clone->collection = array_values(array_filter($this->collection, $closure)); @@ -73,7 +73,7 @@ public function filter(\Closure $closure) : Collection /** * {@inheritdoc} */ - public function toArray() : array + public function toArray(): array { return $this->collection; } @@ -81,7 +81,7 @@ public function toArray() : array /** * {@inheritdoc} */ - public function count() + public function count(): int { return count($this->collection); } @@ -89,12 +89,12 @@ public function count() /** * {@inheritdoc} */ - public function contains($other) : bool + public function contains($other): bool { return in_array($other, $this->collection); } - public function toString() : string + public function toString(): string { return implode(PHP_EOL, $this->mapToArray(function ($x) { return $x->toString(); @@ -104,12 +104,12 @@ public function toString() : string /** * @return string */ - public function __toString() : string + public function __toString(): string { return $this->toString(); } - public function equals(Collection $other) : bool + public function equals(Collection $other): bool { return $this->toString() === $other->toString(); } diff --git a/src/Util/AbstractMap.php b/src/Util/AbstractMap.php index 6f5e089..ec2050e 100644 --- a/src/Util/AbstractMap.php +++ b/src/Util/AbstractMap.php @@ -15,7 +15,7 @@ abstract class AbstractMap implements Collection /** * @inheritDoc */ - public function any(\Closure $closure) : bool + public function any(\Closure $closure): bool { foreach ($this->map as $item) { foreach ($item[self::$VALUE]->toArray() as $subItem) { @@ -30,7 +30,7 @@ public function any(\Closure $closure) : bool /** * @inheritDoc */ - public function none(\Closure $closure) : bool + public function none(\Closure $closure): bool { return !$this->any($closure); } @@ -50,7 +50,7 @@ public function each(\Closure $closure) /** * @inheritDoc */ - public function mapToArray(\Closure $closure) : array + public function mapToArray(\Closure $closure): array { $xs = []; foreach ($this->map as $item) { @@ -77,7 +77,7 @@ public function reduce($initial, \Closure $closure) /** * @inheritDoc */ - public function filter(\Closure $closure) : Collection + public function filter(\Closure $closure): Collection { $clone = clone $this; $clone->map = []; @@ -94,7 +94,7 @@ public function filter(\Closure $closure) : Collection /** * @inheritDoc */ - public function toArray() : array + public function toArray(): array { return $this->map; } @@ -102,7 +102,7 @@ public function toArray() : array /** * @inheritDoc */ - public function contains($other) : bool + public function contains($other): bool { foreach ($this->map as $key => $item) { if ($item[self::$KEY] instanceof $other && $item[self::$KEY]->equals($other)) { @@ -115,12 +115,12 @@ public function contains($other) : bool /** * @inheritDoc */ - abstract public function toString() : string; + abstract public function toString(): string; /** * @inheritDoc */ - public function equals(Collection $other) : bool + public function equals(Collection $other): bool { return $this instanceof $other && $this->toString() === $other->toString(); @@ -129,7 +129,7 @@ public function equals(Collection $other) : bool /** * @inheritDoc */ - public function count() + public function count(): int { return count($this->map); } diff --git a/src/Util/Collection.php b/src/Util/Collection.php index 9ad7a6f..c4dd6f1 100644 --- a/src/Util/Collection.php +++ b/src/Util/Collection.php @@ -13,14 +13,14 @@ interface Collection extends \Countable * * @return bool */ - public function any(\Closure $closure) : bool; + public function any(\Closure $closure): bool; /** * @param \Closure $closure * * @return bool */ - public function none(\Closure $closure) : bool; + public function none(\Closure $closure): bool; /** * Applies $closure to each element. @@ -36,7 +36,7 @@ public function each(\Closure $closure); * * @return array */ - public function mapToArray(\Closure $closure) : array; + public function mapToArray(\Closure $closure): array; /** * @param mixed $initial @@ -51,29 +51,29 @@ public function reduce($initial, \Closure $closure); * * @return Collection */ - public function filter(\Closure $closure) : Collection; + public function filter(\Closure $closure): Collection; /** * @return array */ - public function toArray() : array; + public function toArray(): array; /** * @param $other * * @return bool */ - public function contains($other) : bool; + public function contains($other): bool; /** * @return string */ - public function toString() : string; + public function toString(): string; /** * @param Collection $other * * @return bool */ - public function equals(Collection $other) : bool; + public function equals(Collection $other): bool; } diff --git a/src/Util/Functional.php b/src/Util/Functional.php index 7093d9d..e652d6b 100644 --- a/src/Util/Functional.php +++ b/src/Util/Functional.php @@ -13,7 +13,7 @@ public static function id() }; } - public static function compose(...$functions) : \Closure + public static function compose(...$functions): \Closure { return array_reduce( $functions, diff --git a/src/Util/Util.php b/src/Util/Util.php index 7eb4e2c..ee9275e 100644 --- a/src/Util/Util.php +++ b/src/Util/Util.php @@ -15,7 +15,7 @@ class Util * * @return bool */ - public static function array_once(array $xs, \Closure $fn) : bool + public static function array_once(array $xs, \Closure $fn): bool { foreach ($xs as $index => $value) { if ($fn($value, $index)) { diff --git a/tests/feature/DsmTest.php b/tests/feature/DsmTest.php index 20fcb19..94a6aba 100644 --- a/tests/feature/DsmTest.php +++ b/tests/feature/DsmTest.php @@ -10,7 +10,7 @@ class DsmTest extends TestCase { public function testCreatesSimpleDsmInHtml(): void { - assertRegExp( + $this->assertMatchesRegularExpression( '@\d: PhpParser
([1-9]\d*).+.+@s', shell_exec(DEPHPEND_BIN.' dsm '.SRC_PATH.' --no-classes --depth=2 --format=html') ); diff --git a/tests/feature/HelpTest.php b/tests/feature/HelpTest.php index 77cda37..4b50bf6 100644 --- a/tests/feature/HelpTest.php +++ b/tests/feature/HelpTest.php @@ -10,16 +10,16 @@ class HelpTest extends TestCase { public function testNoArgumentsShowsHelp(): void { - self::assertRegExp('/command \[options\] \[arguments\].*/s', shell_exec(DEPHPEND_BIN)); + $this->assertMatchesRegularExpression('/command \[options\] \[arguments\].*/s', shell_exec(DEPHPEND_BIN)); } public function testHelpShowsHelp(): void { - self::assertRegExp('/Usage:.*Options:.*Help:.*/s', shell_exec(DEPHPEND_BIN.' help')); + $this->assertMatchesRegularExpression('/Usage:.*Options:.*Help:.*/s', shell_exec(DEPHPEND_BIN.' help')); } public function testShowsHelpForCommand(): void { - self::assertRegExp('/Arguments:.*source.*Options:.*--internals.*/s', shell_exec(DEPHPEND_BIN.' help text')); + $this->assertMatchesRegularExpression('/Arguments:.*source.*Options:.*--internals.*/s', shell_exec(DEPHPEND_BIN.' help text')); } } diff --git a/tests/feature/ListTest.php b/tests/feature/ListTest.php index a441fcf..94dd0f5 100644 --- a/tests/feature/ListTest.php +++ b/tests/feature/ListTest.php @@ -10,6 +10,6 @@ class ListTest extends TestCase { public function testNoArgumentsShowsHelp(): void { - assertRegExp('/dsm.*metrics.*text.*uml.*/s', shell_exec(DEPHPEND_BIN.' list')); + $this->assertMatchesRegularExpression('/dsm.*metrics.*text.*uml.*/s', shell_exec(DEPHPEND_BIN.' list')); } } diff --git a/tests/feature/MetricsTest.php b/tests/feature/MetricsTest.php index c6e84f4..8bacf17 100644 --- a/tests/feature/MetricsTest.php +++ b/tests/feature/MetricsTest.php @@ -10,7 +10,7 @@ class MetricsTest extends TestCase { public function testComputeMetricsForDephpend(): void { - assertRegExp( + $this->assertMatchesRegularExpression( '/Classes:.*\d\d.*Abstract classes:.*\d+.*Abstractness:.*\d\.\d+/s', shell_exec(DEPHPEND_BIN.' metrics '.SRC_PATH) ); diff --git a/tests/feature/TextTest.php b/tests/feature/TextTest.php index cc8dbd8..b6c57bd 100644 --- a/tests/feature/TextTest.php +++ b/tests/feature/TextTest.php @@ -8,10 +8,9 @@ class TextTest extends TestCase { - public function testTextCommandOnDephpendSourceWithoutClassesAndWithRegexAndFromFilter(): void { - assertEquals( + $this->assertEquals( 'Mihaeu\PhpDependencies\Analyser --> Mihaeu\PhpDependencies\Dependencies'.PHP_EOL .'Mihaeu\PhpDependencies\Analyser --> Mihaeu\PhpDependencies\OS'.PHP_EOL, shell_exec(DEPHPEND_BIN.' text '.SRC_PATH diff --git a/tests/feature/UmlTest.php b/tests/feature/UmlTest.php index 9a22316..d850b82 100644 --- a/tests/feature/UmlTest.php +++ b/tests/feature/UmlTest.php @@ -44,7 +44,7 @@ public function testCreatesUml(): void $tempFileUml = sys_get_temp_dir().'/dephpend-uml-test.uml'; shell_exec(DEPHPEND_BIN.' uml '.SRC_PATH.' --no-classes --keep-uml ' .'--output="'.$tempFilePng.'" -f Mihaeu\\\\PhpDependencies\\\\OS'); - assertEquals( + $this->assertEquals( $expected, file_get_contents($tempFileUml) ); diff --git a/tests/samples/CreatingObjectsFeature.php b/tests/samples/CreatingObjectsFeature.php index 84155d0..eb8c548 100644 --- a/tests/samples/CreatingObjectsFeature.php +++ b/tests/samples/CreatingObjectsFeature.php @@ -7,6 +7,6 @@ class A public function test(): void { new B(); - new C; + new C(); } } diff --git a/tests/samples/KnownVariablePassedIntoMethodWithoutTypeHintsFeature.php b/tests/samples/KnownVariablePassedIntoMethodWithoutTypeHintsFeature.php index 9915c50..2b5fa43 100644 --- a/tests/samples/KnownVariablePassedIntoMethodWithoutTypeHintsFeature.php +++ b/tests/samples/KnownVariablePassedIntoMethodWithoutTypeHintsFeature.php @@ -7,7 +7,7 @@ class A { public function test(): void { - $b = new B; + $b = new B(); new C($b); } } diff --git a/tests/samples/ParamReturnThrowsInDocCommentFeature.php b/tests/samples/ParamReturnThrowsInDocCommentFeature.php index 6e720a3..68bac63 100644 --- a/tests/samples/ParamReturnThrowsInDocCommentFeature.php +++ b/tests/samples/ParamReturnThrowsInDocCommentFeature.php @@ -1,4 +1,6 @@ - A +createMock(Parser::class); $baseParser->method('parse')->willReturn(['test']); $parser = new DefaultParser($baseParser); - assertEquals(['test'], $parser->parse('')); + $this->assertEquals(['test'], $parser->parse('')); } } diff --git a/tests/unit/Analyser/DependencyInspectionVisitorTest.php b/tests/unit/Analyser/DependencyInspectionVisitorTest.php index 99611ae..5ebc2cf 100644 --- a/tests/unit/Analyser/DependencyInspectionVisitorTest.php +++ b/tests/unit/Analyser/DependencyInspectionVisitorTest.php @@ -77,7 +77,7 @@ protected function setUp(): void * * @return bool */ - private function dependenciesContain(DependencyMap $dependencies, Dependency $otherDependency) : bool + private function dependenciesContain(DependencyMap $dependencies, Dependency $otherDependency): bool { return $dependencies->any(function (Dependency $from, Dependency $to) use ($otherDependency) { return $from->equals($otherDependency) @@ -122,7 +122,7 @@ public function testDetectsExplicitNewCreation(): void $this->dependencyInspectionVisitor->enterNode($newNode); $this->dependencyInspectionVisitor->leaveNode($node); - assertTrue($this->dependenciesContain($this->dependencyInspectionVisitor->dependencies(), new Clazz('TestDep'))); + $this->assertTrue($this->dependenciesContain($this->dependencyInspectionVisitor->dependencies(), new Clazz('TestDep'))); } public function testDetectsExtendedClasses(): void @@ -136,7 +136,7 @@ public function testDetectsExtendedClasses(): void $this->dependencyInspectionVisitor->enterNode($node); $this->dependencyInspectionVisitor->leaveNode($node); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Clazz('ClassA', new Namespaze(['A', 'a', '1'])) )); @@ -157,11 +157,11 @@ public function testDetectsWhenInterfacesImplementMultipleInterfaces(): void $this->dependencyInspectionVisitor->enterNode($node); $this->dependencyInspectionVisitor->leaveNode($node); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Clazz('ClassA', new Namespaze(['A', 'a', '1'])) )); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Clazz('ClassB', new Namespaze(['B', 'b', '2'])) )); @@ -177,7 +177,7 @@ public function testDetectsAbstractClasses(): void $this->addRandomDependency(); $this->dependencyInspectionVisitor->leaveNode($node); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new AbstractClazz('Test', new Namespaze(['A'])) )); @@ -193,7 +193,7 @@ public function testDetectsInterfaces(): void $this->addRandomDependency(); $this->dependencyInspectionVisitor->leaveNode($node); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Interfaze('Test', new Namespaze(['A'])) )); @@ -213,11 +213,11 @@ public function testDetectsImplementedInterfaces(): void $this->dependencyInspectionVisitor->enterNode($node); $this->dependencyInspectionVisitor->leaveNode($node); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Clazz('InterfaceOne', new Namespaze(['A', 'B'])) )); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Clazz('InterfaceTwo', new Namespaze(['C', 'D'])) )); @@ -229,7 +229,7 @@ public function testIgnoresInnerClassesWithoutName(): void $this->dependencyInspectionVisitor->enterNode($node); $this->dependencyInspectionVisitor->leaveNode($node); - assertEmpty($this->dependencyInspectionVisitor->dependencies()); + $this->assertEmpty($this->dependencyInspectionVisitor->dependencies()); } public function testDetectsDependenciesFromMethodArguments(): void @@ -248,11 +248,11 @@ public function testDetectsDependenciesFromMethodArguments(): void $this->addNodeToAst($methodNode); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Clazz('DependencyOne', new Namespaze(['A', 'B'])) )); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Clazz('DependencyTwo', new Namespaze(['A', 'B'])) )); @@ -266,7 +266,7 @@ public function testDetectsUseNodes(): void ) ); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Clazz('Test', new Namespaze(['A', 'a', '1'])) )); @@ -278,7 +278,7 @@ public function testReturnType(): void new ClassMethod('', ['returnType' => new Name(['Namespace', 'Test'])]) ); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Clazz('Test', new Namespaze(['Namespace'])) )); @@ -293,7 +293,7 @@ public function testDetectsCallsOnStaticClasses(): void $this->dependencyInspectionVisitor->enterNode($staticCall); $this->dependencyInspectionVisitor->leaveNode($node); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Clazz('Singleton', new Namespaze(['A', 'a', '1'])) )); @@ -307,7 +307,7 @@ public function testAddsDependenciesOnlyWhenInClassContext(): void // we leave the ClassNode, but we haven't entered it, so class context is unknown $this->dependencyInspectionVisitor->leaveNode(new ClassNode('test')); $dependencies = $this->dependencyInspectionVisitor->dependencies(); - assertEmpty($dependencies); + $this->assertEmpty($dependencies); } public function testTrait(): void @@ -320,7 +320,7 @@ public function testTrait(): void $this->addRandomDependency(); $this->dependencyInspectionVisitor->leaveNode($node); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Trait_('Test', new Namespaze(['A'])) )); @@ -332,7 +332,7 @@ public function testUseSingleTrait(): void new TraitUse([new Name(['A', 'Test'])]) ); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Trait_('Test', new Namespaze(['A'])) )); @@ -348,15 +348,15 @@ public function testUseMultipleTraits(): void ]) ); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Trait_('Test', new Namespaze(['A'])) )); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Trait_('Test2', new Namespaze(['B'])) )); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Trait_('Test3', new Namespaze(['C'])) )); @@ -368,7 +368,7 @@ public function testUseInstanceofComparison(): void new Instanceof_(new Array_(), new FullyQualifiedNameNode('Test')) ); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Clazz('Test') )); @@ -380,7 +380,7 @@ public function testDetectsCatchNode(): void new Catch_([new Name(['AnException'])], new Variable('e')) ); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Clazz('AnException') )); @@ -395,11 +395,11 @@ public function testDetectsPhp71MultipleCatchNodes(): void ], new Variable('e')) ); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Clazz('AnException') )); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Clazz('AnotherException') )); @@ -411,7 +411,7 @@ public function testDetectsFetchClassNode(): void new ClassConstFetch(new Name('StaticTest'), 'test') ); - assertTrue($this->dependenciesContain( + $this->assertTrue($this->dependenciesContain( $this->dependencyInspectionVisitor->dependencies(), new Clazz('StaticTest') )); diff --git a/tests/unit/Analyser/MetricsTest.php b/tests/unit/Analyser/MetricsTest.php index 63db362..b016f95 100644 --- a/tests/unit/Analyser/MetricsTest.php +++ b/tests/unit/Analyser/MetricsTest.php @@ -39,27 +39,27 @@ protected function setUp(): void public function testAbstractnessWithNoDependency(): void { - assertEquals(0, (new Metrics)->abstractness(new DependencyMap)); + $this->assertEquals(0, (new Metrics())->abstractness(new DependencyMap())); } public function testCountClasses(): void { - assertEquals(4, $this->metrics->classCount($this->dependencies)); + $this->assertEquals(4, $this->metrics->classCount($this->dependencies)); } public function testCountInterfaces(): void { - assertEquals(1, $this->metrics->interfaceCount($this->dependencies)); + $this->assertEquals(1, $this->metrics->interfaceCount($this->dependencies)); } public function testCountAbstractClasses(): void { - assertEquals(1, $this->metrics->abstractClassCount($this->dependencies)); + $this->assertEquals(1, $this->metrics->abstractClassCount($this->dependencies)); } public function testCountTraits(): void { - assertEquals(1, $this->metrics->traitCount($this->dependencies)); + $this->assertEquals(1, $this->metrics->traitCount($this->dependencies)); } public function testComputeAbstractness(): void @@ -69,7 +69,7 @@ public function testComputeAbstractness(): void public function testComputeAfferentCoupling(): void { - assertEquals([ + $this->assertEquals([ 'A' => 0, 'G' => 0, 'R' => 0, @@ -83,7 +83,7 @@ public function testComputeAfferentCoupling(): void public function testComputeEfferentCoupling(): void { // all my classes depend only on one dependency - assertEquals([ + $this->assertEquals([ 'A' => 1, 'G' => 1, 'R' => 1, @@ -96,7 +96,7 @@ public function testComputeEfferentCoupling(): void public function testComputeInstability(): void { - assertEquals([ + $this->assertEquals([ 'A' => 1, 'G' => 1, 'R' => 1, diff --git a/tests/unit/Analyser/StaticAnalyserTest.php b/tests/unit/Analyser/StaticAnalyserTest.php index f3e0e53..cea64e5 100644 --- a/tests/unit/Analyser/StaticAnalyserTest.php +++ b/tests/unit/Analyser/StaticAnalyserTest.php @@ -47,7 +47,7 @@ public function testAnalyse(): void $phpFile = $this->createMock(PhpFile::class); $phpFile->method('code')->willReturn(''); $dependencies = $this->analyser->analyse((new PhpFileSet())->add($phpFile)); - assertEquals(new DependencyMap(), $dependencies); + $this->assertEquals(new DependencyMap(), $dependencies); } public function testEnrichesExceptionWhenParserThrows(): void diff --git a/tests/unit/Analyser/XDebugFunctionTraceAnalyserTest.php b/tests/unit/Analyser/XDebugFunctionTraceAnalyserTest.php index 3e6246d..4507315 100644 --- a/tests/unit/Analyser/XDebugFunctionTraceAnalyserTest.php +++ b/tests/unit/Analyser/XDebugFunctionTraceAnalyserTest.php @@ -1,4 +1,6 @@ -c', 6, 7, 8, 9, 10, 'class A'], [0, 1, 2, 3, 4, 'D->c', 6, 7, 8, 9, 10, 'class A'], ]); - assertEquals( + $this->assertEquals( DependencyHelper::map(' B --> A D --> A @@ -58,7 +60,7 @@ public function testAnalyseIgnoresScalarValues(): void [0, 1, 2, 3, 4, 'D->c', 6, 7, 8, 9, 10, 'int'], [0, 1, 2, 3, 4, 'D->c', 6, 7, 8, 9, 10, 'resource'], ]); - assertEquals( + $this->assertEquals( DependencyHelper::map(' B --> A '), @@ -74,7 +76,7 @@ public function testThrowsExceptionIfFileCannotBeOpened(): void $this->xDebugFunctionTraceAnalyser->analyse($tmpFile); } - private function createContent(array $data) : string + private function createContent(array $data): string { return array_reduce($data, function (string $carry, array $lineParts) { return $carry.implode("\t", $lineParts).PHP_EOL; diff --git a/tests/unit/Cli/ApplicationTest.php b/tests/unit/Cli/ApplicationTest.php index ea25072..1bbc134 100644 --- a/tests/unit/Cli/ApplicationTest.php +++ b/tests/unit/Cli/ApplicationTest.php @@ -56,9 +56,9 @@ public function testWarningIfXDebugEnabled(): void // not sure how to mock this, so we test only one case, there's always one error message regarding // Symfony console setup, so if there's no xdebug loaded we still see one message if (!extension_loaded('xdebug')) { - $errorOutput->expects(once())->method('writeln'); + $errorOutput->expects($this->once())->method('writeln'); } else { - $errorOutput->expects(exactly(2))->method('writeln'); + $errorOutput->expects($this->exactly(2))->method('writeln'); } $this->application->doRun($this->input, $this->output); } @@ -76,9 +76,9 @@ public function testPrintsErrorMessageIfParserThrowsException(): void $errorOutput = $this->createMock(ErrorOutput::class); $this->application->setErrorOutput($errorOutput); if (!extension_loaded('xdebug')) { - $errorOutput->expects(once())->method('writeln')->with($expectedMessage); + $errorOutput->expects($this->once())->method('writeln')->with($expectedMessage); } else { - $errorOutput->expects(exactly(2))->method('writeln')->withConsecutive( + $errorOutput->expects($this->exactly(2))->method('writeln')->withConsecutive( [self::XDEBUG_WARNING], [$expectedMessage] ); @@ -95,7 +95,7 @@ public function testValidatesDsmInput(): void $application->setErrorOutput($errorOutput); $returnCode = $application->doRun($this->input, $this->output); - assertEquals(0, $returnCode); + $this->assertEquals(0, $returnCode); } public function testValidatesUmlInput(): void @@ -107,7 +107,7 @@ public function testValidatesUmlInput(): void $application->setErrorOutput($errorOutput); $returnCode = $application->doRun($this->input, $this->output); - assertEquals(0, $returnCode); + $this->assertEquals(0, $returnCode); } public function testValidatesMetricInput(): void @@ -119,7 +119,7 @@ public function testValidatesMetricInput(): void $application->setErrorOutput($errorOutput); $returnCode = $application->doRun($this->input, $this->output); - assertEquals(0, $returnCode); + $this->assertEquals(0, $returnCode); } public function testValidatesDotInput(): void @@ -131,7 +131,7 @@ public function testValidatesDotInput(): void $application->setErrorOutput($errorOutput); $returnCode = $application->doRun($this->input, $this->output); - assertEquals(0, $returnCode); + $this->assertEquals(0, $returnCode); } public function testCommandWithHelpOptionProvidesHelpForDotCommand(): void @@ -149,7 +149,7 @@ public function testNoCommandWithVersionOptionWritesVersion(): void $input = new ArgvInput(['', '--version']); $output = new BufferedOutput(); (new Application('Test', '4.2.0', $this->dispatcher))->doRun($input, $output); - assertRegExp('/\d+\.\d+\.\d+/', $output->fetch()); + $this->assertMatchesRegularExpression('/\d+\.\d+\.\d+/', $output->fetch()); } public function testNoCommandWithHelpOptionWritesHelp(): void diff --git a/tests/unit/Cli/DispatcherTest.php b/tests/unit/Cli/DispatcherTest.php index 9e2c6fa..799ac12 100644 --- a/tests/unit/Cli/DispatcherTest.php +++ b/tests/unit/Cli/DispatcherTest.php @@ -53,14 +53,14 @@ protected function setUp(): void public function testTriggersOnlyOnNamedConsoleEvents(): void { $consoleEvent = $this->createMock(ConsoleEvent::class); - $consoleEvent->expects(never())->method('getInput'); + $consoleEvent->expects($this->never())->method('getInput'); $this->dispatcher->dispatch($consoleEvent, 'other event'); } public function testTriggersOnlyOnConsoleEvents(): void { $consoleEvent = $this->createMock(GenericEvent::class); - assertEquals( + $this->assertEquals( $consoleEvent, $this->dispatcher->dispatch(clone $consoleEvent, ConsoleEvents::COMMAND) ); @@ -80,9 +80,9 @@ public function testInjectsDependenciesIntoConsoleEvents(): void $input->method('getOption')->with('dynamic')->willReturn($traceFile); $consoleEvent->method('getInput')->willReturn($input); - $this->xDebugFunctionTraceAnalyser->expects(once())->method('analyse')->with($traceFile); - $command->expects(once())->method('setDependencies'); - $command->expects(once())->method('setPostProcessors'); + $this->xDebugFunctionTraceAnalyser->expects($this->once())->method('analyse')->with($traceFile); + $command->expects($this->once())->method('setDependencies'); + $command->expects($this->once())->method('setPostProcessors'); $this->dispatcher->dispatch(clone $consoleEvent, ConsoleEvents::COMMAND); } } diff --git a/tests/unit/Cli/DotCommandTest.php b/tests/unit/Cli/DotCommandTest.php index c6185f2..77148b8 100644 --- a/tests/unit/Cli/DotCommandTest.php +++ b/tests/unit/Cli/DotCommandTest.php @@ -44,7 +44,7 @@ public function testGenerateDot(): void 'filter-namespace' => null, 'depth' => 0 ]); - $this->dotWrapper->expects(once())->method('generate'); + $this->dotWrapper->expects($this->once())->method('generate'); $this->dotCommand->run( $this->input, diff --git a/tests/unit/Cli/DsmCommandTest.php b/tests/unit/Cli/DsmCommandTest.php index 9a1d195..c54ecce 100644 --- a/tests/unit/Cli/DsmCommandTest.php +++ b/tests/unit/Cli/DsmCommandTest.php @@ -57,7 +57,7 @@ public function testPassesDependenciesToFormatter(): void $dependencies = DependencyHelper::map('A --> B'); $this->dsmCommand->setDependencies($dependencies); - $this->dependencyStructureMatrixFormatter->expects(once())->method('format')->with($dependencies); + $this->dependencyStructureMatrixFormatter->expects($this->once())->method('format')->with($dependencies); $this->dsmCommand->run($this->input, $this->output); } diff --git a/tests/unit/Cli/MetricsCommandTest.php b/tests/unit/Cli/MetricsCommandTest.php index 9821316..15dc5ef 100644 --- a/tests/unit/Cli/MetricsCommandTest.php +++ b/tests/unit/Cli/MetricsCommandTest.php @@ -53,7 +53,7 @@ public function testPrintsMetrics(): void $output = new BufferedOutput(); $this->metricsCommand->run($this->input, $output); - assertEquals( + $this->assertEquals( '+--------------------+-------+ | Classes: | 1 | | Abstract classes: | 2 | diff --git a/tests/unit/Cli/TextCommandTest.php b/tests/unit/Cli/TextCommandTest.php index 58a9ef6..c8e20ca 100644 --- a/tests/unit/Cli/TextCommandTest.php +++ b/tests/unit/Cli/TextCommandTest.php @@ -52,7 +52,7 @@ public function testPrintsDependencies(): void $this->input->method('getOption')->willReturn(false, 0); $this->input->method('getOptions')->willReturn(['internals' => false, 'filter-namespace' => null, 'depth' => 0]); - $this->output->expects(once()) + $this->output->expects($this->once()) ->method('writeln') ->with( 'A\\a\\1\\ClassA --> B\\a\\1\\ClassB'.PHP_EOL @@ -75,7 +75,7 @@ public function testPrintsOnlyNamespacedDependencies(): void $this->input->method('getArgument')->willReturn([sys_get_temp_dir()]); $this->input->method('getOptions')->willReturn(['internals' => false, 'filter-namespace' => null, 'depth' => 1]); - $this->output->expects(once()) + $this->output->expects($this->once()) ->method('writeln') ->with( 'NamespaceA --> NamespaceB'.PHP_EOL diff --git a/tests/unit/Cli/UmlCommandTest.php b/tests/unit/Cli/UmlCommandTest.php index 9197b50..140fc7f 100644 --- a/tests/unit/Cli/UmlCommandTest.php +++ b/tests/unit/Cli/UmlCommandTest.php @@ -86,7 +86,7 @@ public function testGenerateUml(): void 'filter-namespace' => null, 'depth' => 0 ]); - $this->plantUmlWrapper->expects(once())->method('generate'); + $this->plantUmlWrapper->expects($this->once())->method('generate'); $this->umlCommand->run( $this->input, diff --git a/tests/unit/Dependencies/ClazzTest.php b/tests/unit/Dependencies/ClazzTest.php index 8d271ab..d3a9b1e 100644 --- a/tests/unit/Dependencies/ClazzTest.php +++ b/tests/unit/Dependencies/ClazzTest.php @@ -18,58 +18,58 @@ class ClazzTest extends TestCase { public function testAcceptsUtf8Name(): void { - assertEquals('á', (new Clazz('á'))->toString()); + $this->assertEquals('á', (new Clazz('á'))->toString()); } public function testHasValue(): void { - assertEquals('Name', new Clazz('Name')); - assertEquals('Name', (new Clazz('Name'))->toString()); + $this->assertEquals('Name', new Clazz('Name')); + $this->assertEquals('Name', (new Clazz('Name'))->toString()); } public function testNamespace(): void { - assertEquals(new Namespaze(['A', 'a']), (new Clazz('Name', new Namespaze(['A', 'a'])))->namespaze()); + $this->assertEquals(new Namespaze(['A', 'a']), (new Clazz('Name', new Namespaze(['A', 'a'])))->namespaze()); } public function testToStringWithNamespace(): void { - assertEquals('A\\a\\ClassA', new Clazz('ClassA', new Namespaze(['A', 'a']))); + $this->assertEquals('A\\a\\ClassA', new Clazz('ClassA', new Namespaze(['A', 'a']))); } public function testEquals(): void { - assertTrue((new Clazz('A'))->equals(new Clazz('A'))); + $this->assertTrue((new Clazz('A'))->equals(new Clazz('A'))); } public function testEqualsIgnoresType(): void { - assertTrue((new Clazz('A'))->equals(new Interfaze('A'))); + $this->assertTrue((new Clazz('A'))->equals(new Interfaze('A'))); } public function testDetectsIfClassHasNamespace(): void { - assertTrue((new Clazz('Class', new Namespaze(['A'])))->hasNamespace()); + $this->assertTrue((new Clazz('Class', new Namespaze(['A'])))->hasNamespace()); } public function testDetectsIfClassHasNoNamespace(): void { - assertFalse((new Clazz('Class'))->hasNamespace()); + $this->assertFalse((new Clazz('Class'))->hasNamespace()); } public function testDepthWithoutNamespaceIsOne(): void { - assertCount(1, new Clazz('A')); + $this->assertCount(1, new Clazz('A')); } public function testDepthWithNamespace(): void { - assertCount(3, new Clazz('A', new Namespaze(['B', 'C']))); + $this->assertCount(3, new Clazz('A', new Namespaze(['B', 'C']))); } public function testReduceWithDepthZero(): void { - assertEquals( + $this->assertEquals( H::clazz('A\\B\\C\\D'), H::clazz('A\\B\\C\\D')->reduceToDepth(0) ); @@ -77,13 +77,13 @@ public function testReduceWithDepthZero(): void public function testReduceToDepthTwoWithoutNamespacesProducesClass(): void { - assertEquals(new Clazz('A'), (new Clazz('A'))->reduceToDepth(2)); + $this->assertEquals(new Clazz('A'), (new Clazz('A'))->reduceToDepth(2)); } public function testReduceDepthToTwoProducesTopTwoNamespaces(): void { $clazz = H::clazz('A\\B\\C\\D'); - assertEquals( + $this->assertEquals( new Namespaze(['A', 'B']), $clazz->reduceToDepth(2) ); @@ -91,7 +91,7 @@ public function testReduceDepthToTwoProducesTopTwoNamespaces(): void public function testReduceToDepthOfOneProducesOneNamespace(): void { - assertEquals( + $this->assertEquals( new Namespaze(['A']), H::clazz('A\\B\\C\\D')->reduceToDepth(1) ); @@ -99,7 +99,7 @@ public function testReduceToDepthOfOneProducesOneNamespace(): void public function testLeftReduceClassWithNamespace(): void { - assertEquals( + $this->assertEquals( H::clazz('D'), H::clazz('A\\B\\C\\D')->reduceDepthFromLeftBy(3) ); @@ -107,7 +107,7 @@ public function testLeftReduceClassWithNamespace(): void public function testCannotLeftReduceClassWithNamespaceByItsLength(): void { - assertEquals( + $this->assertEquals( H::clazz('A\\B\\C\\D'), H::clazz('A\\B\\C\\D')->reduceDepthFromLeftBy(4) ); @@ -118,12 +118,12 @@ public function testCannotLeftReduceClassWithNamespaceByItsLength(): void */ public function testAcceptsNumbersAsFirstCharacterInName(): void { - assertEquals('Vendor\\1Sub\\2Factor', new Clazz('2Factor', new Namespaze(['Vendor', '1Sub']))); + $this->assertEquals('Vendor\\1Sub\\2Factor', new Clazz('2Factor', new Namespaze(['Vendor', '1Sub']))); } public function testCannotLeftReduceClassWithNamespaceByMoreThanItsLength(): void { - assertEquals( + $this->assertEquals( H::clazz('A\\B\\C\\D'), H::clazz('A\\B\\C\\D')->reduceDepthFromLeftBy(5) ); @@ -131,14 +131,14 @@ public function testCannotLeftReduceClassWithNamespaceByMoreThanItsLength(): voi public function testDetectsIfInOtherNamespace(): void { - assertTrue(DependencyHelper::clazz('A\\b\\T\\Test')->inNamespaze(DependencyHelper::namespaze('A\\b'))); - assertTrue(DependencyHelper::clazz('A\\Test')->inNamespaze(DependencyHelper::namespaze('A'))); - assertTrue(DependencyHelper::clazz(Collection::class)->inNamespaze(new Namespaze(['Mihaeu', 'PhpDependencies']))); + $this->assertTrue(DependencyHelper::clazz('A\\b\\T\\Test')->inNamespaze(DependencyHelper::namespaze('A\\b'))); + $this->assertTrue(DependencyHelper::clazz('A\\Test')->inNamespaze(DependencyHelper::namespaze('A'))); + $this->assertTrue(DependencyHelper::clazz(Collection::class)->inNamespaze(new Namespaze(['Mihaeu', 'PhpDependencies']))); } public function testDetectsIfNotInOtherNamespace(): void { - assertFalse(DependencyHelper::clazz('Global')->inNamespaze(DependencyHelper::namespaze('A\\b\\T'))); + $this->assertFalse(DependencyHelper::clazz('Global')->inNamespaze(DependencyHelper::namespaze('A\\b\\T'))); } public function testThrowsExceptionIfNameNotValid(): void @@ -150,11 +150,11 @@ public function testThrowsExceptionIfNameNotValid(): void public function testDetectsIfClassIsNotNamespaced(): void { - assertFalse((new Clazz('NoNamespace'))->isNamespaced()); + $this->assertFalse((new Clazz('NoNamespace'))->isNamespaced()); } public function testDetectsIfClassIsNamespaced(): void { - assertTrue((new Clazz('HasNamespace', new Namespaze(['Vendor'])))->isNamespaced()); + $this->assertTrue((new Clazz('HasNamespace', new Namespaze(['Vendor'])))->isNamespaced()); } } diff --git a/tests/unit/Dependencies/DependencyFactoryTest.php b/tests/unit/Dependencies/DependencyFactoryTest.php index 1a02dde..bf231ec 100644 --- a/tests/unit/Dependencies/DependencyFactoryTest.php +++ b/tests/unit/Dependencies/DependencyFactoryTest.php @@ -21,7 +21,7 @@ protected function setUp(): void public function testInvalidClassReturnsNullDependency(): void { - assertInstanceOf( + $this->assertInstanceOf( NullDependency::class, $this->clazzFactory->createClazzFromStringArray(['/']) ); @@ -29,12 +29,12 @@ public function testInvalidClassReturnsNullDependency(): void public function testCreatesClazzWithEmptyNamespace(): void { - assertEquals(new Clazz('Test', new Namespaze([])), $this->clazzFactory->createClazzFromStringArray(['Test'])); + $this->assertEquals(new Clazz('Test', new Namespaze([])), $this->clazzFactory->createClazzFromStringArray(['Test'])); } public function testCreateClazzWithNamespace(): void { - assertEquals( + $this->assertEquals( new Clazz('Test', new Namespaze(['Mihaeu', 'PhpDependencies'])), $this->clazzFactory->createClazzFromStringArray(['Mihaeu', 'PhpDependencies', 'Test']) ); @@ -42,16 +42,16 @@ public function testCreateClazzWithNamespace(): void public function testCreateInterfaze(): void { - assertEquals(new AbstractClazz('Test', new Namespaze([])), $this->clazzFactory->createAbstractClazzFromStringArray(['Test'])); + $this->assertEquals(new AbstractClazz('Test', new Namespaze([])), $this->clazzFactory->createAbstractClazzFromStringArray(['Test'])); } public function testCreateAbstractClazz(): void { - assertEquals(new Interfaze('Test', new Namespaze([])), $this->clazzFactory->createInterfazeFromStringArray(['Test'])); + $this->assertEquals(new Interfaze('Test', new Namespaze([])), $this->clazzFactory->createInterfazeFromStringArray(['Test'])); } public function testCreateTrait(): void { - assertEquals(new Trait_('Test', new Namespaze([])), $this->clazzFactory->createTraitFromStringArray(['Test'])); + $this->assertEquals(new Trait_('Test', new Namespaze([])), $this->clazzFactory->createTraitFromStringArray(['Test'])); } } diff --git a/tests/unit/Dependencies/DependencyFilterTest.php b/tests/unit/Dependencies/DependencyFilterTest.php index 1e5cdc6..d4e0a37 100644 --- a/tests/unit/Dependencies/DependencyFilterTest.php +++ b/tests/unit/Dependencies/DependencyFilterTest.php @@ -25,7 +25,7 @@ public function testRemovesInternals(): void { $dependencies = DependencyHelper::map('From --> To, SplFileInfo'); $expected = (new DependencyMap())->add(new Clazz('From'), new Clazz('To')); - assertEquals($expected, $this->filter->removeInternals($dependencies)); + $this->assertEquals($expected, $this->filter->removeInternals($dependencies)); } public function testFilterByDepthOne(): void @@ -39,12 +39,12 @@ public function testFilterByDepthOne(): void _B --> SplFileInfo '); $actual = $this->filter->filterByDepth($dependencies, 1); - assertEquals($expected, $actual); + $this->assertEquals($expected, $actual); } public function testMapUnderscoreNamespaces(): void { - assertEquals( + $this->assertEquals( DependencyHelper::map(' A\\b\\c --> D\\e\\f F\\a --> D\\b @@ -58,7 +58,7 @@ public function testMapUnderscoreNamespaces(): void public function testMapUnderscoreNamespacesAlreadyNamespace(): void { - assertEquals( + $this->assertEquals( DependencyHelper::map(' VendorA\\Tests\\DDC1209_1 --> a\\To A\\__b__\\c --> D\\e\\f @@ -77,7 +77,7 @@ public function testFilterByDepthThree(): void '); $expected = DependencyHelper::map('_VendorA\\ProjectA\\PathA --> _VendorB\\ProjectB\\PathB'); $actual = $this->filter->filterByDepth($dependencies, 3); - assertEquals($expected, $actual); + $this->assertEquals($expected, $actual); } public function testFilterByVendor(): void @@ -90,7 +90,7 @@ public function testFilterByVendor(): void $expected = DependencyHelper::map(' VendorA\\A --> VendorA\\C '); - assertEquals($expected, $this->filter->filterByNamespace($dependencies, 'VendorA')); + $this->assertEquals($expected, $this->filter->filterByNamespace($dependencies, 'VendorA')); } public function testFilterByDepth0ReturnsEqual(): void @@ -101,7 +101,7 @@ public function testFilterByDepth0ReturnsEqual(): void VendorB\\B --> VendorA\\A VendorC\\C --> VendorA\\A '); - assertEquals($dependencies, $this->filter->filterByDepth($dependencies, 0)); + $this->assertEquals($dependencies, $this->filter->filterByDepth($dependencies, 0)); } public function testRemoveClasses(): void { @@ -114,12 +114,12 @@ public function testRemoveClasses(): void VendorB\\B --> VendorA\\A VendorC\\C --> B ')); - assertEquals($expected, $actual); + $this->assertEquals($expected, $actual); } public function testFilterFromDependencies(): void { - assertEquals(DependencyHelper::map(' + $this->assertEquals(DependencyHelper::map(' Good\\A --> Bad\\B Good\\B --> Good\\C '), $this->filter->filterByFromNamespace(DependencyHelper::map(' @@ -166,12 +166,12 @@ public function testRunAllFilters(): void A\\a\\z --> A\\b\\z A\\b\\c --> A\\b\\z '); - assertEquals($expected, $actual); + $this->assertEquals($expected, $actual); } public function testExcludeByRegex(): void { - assertEquals(DependencyHelper::map(' + $this->assertEquals(DependencyHelper::map(' X --> Z '), $this->filter->excludeByRegex(DependencyHelper::map(' Test\\A --> B @@ -186,6 +186,6 @@ public function testExcludeByRegex(): void public function testPostFilters(): void { $filters = $this->filter->postFiltersByOptions(['no-classes' => true, 'depth' => 1]); - assertEquals(new Namespaze(['A']), $filters(new Clazz('Test', new Namespaze(['A', 'a'])))); + $this->assertEquals(new Namespaze(['A']), $filters(new Clazz('Test', new Namespaze(['A', 'a'])))); } } diff --git a/tests/unit/Dependencies/DependencyMapTest.php b/tests/unit/Dependencies/DependencyMapTest.php index 1200176..7591c33 100644 --- a/tests/unit/Dependencies/DependencyMapTest.php +++ b/tests/unit/Dependencies/DependencyMapTest.php @@ -19,12 +19,12 @@ public function testNoDuplicates(): void A --> B B --> C '); - assertEquals($map, $map->add(new Clazz('A'), new Clazz('B'))); + $this->assertEquals($map, $map->add(new Clazz('A'), new Clazz('B'))); } public function testAddMapToMap(): void { - assertEquals(DependencyHelper::map(' + $this->assertEquals(DependencyHelper::map(' A --> B, C B --> C '), DependencyHelper::map(' @@ -38,7 +38,7 @@ public function testAddMapToMap(): void public function testAddMoreDependenciesToExistingPair(): void { $map = DependencyHelper::map('A --> B'); - assertEquals( + $this->assertEquals( DependencyHelper::map('A --> B, C, D'), $map->addSet(new Clazz('A'), DependencyHelper::dependencySet('C, D')) ); @@ -46,14 +46,14 @@ public function testAddMoreDependenciesToExistingPair(): void public function testDoesNotAcceptDependenciesMappingToThemselves(): void { - assertCount(0, DependencyHelper::map('')->add(new Clazz('A'), new Clazz('A'))); + $this->assertCount(0, DependencyHelper::map('')->add(new Clazz('A'), new Clazz('A'))); } public function testReturnsTrueIfAnyMatches(): void { $toSet = DependencyHelper::dependencySet('To, ToAnother'); $dependencies = (new DependencyMap())->addSet(new Clazz('Test'), $toSet); - assertTrue($dependencies->any(function (Dependency $from, Dependency $to) use ($toSet) { + $this->assertTrue($dependencies->any(function (Dependency $from, Dependency $to) use ($toSet) { return $toSet->contains($to); })); } @@ -61,7 +61,7 @@ public function testReturnsTrueIfAnyMatches(): void public function testReturnsTrueIfNoneMatches(): void { $dependencies = (new DependencyMap())->addSet(new Clazz('Test'), DependencyHelper::dependencySet('To, ToAnother')); - assertTrue($dependencies->none(function (Dependency $from, Dependency $to) { + $this->assertTrue($dependencies->none(function (Dependency $from, Dependency $to) { return $from === new Clazz('Other'); })); } @@ -69,14 +69,14 @@ public function testReturnsTrueIfNoneMatches(): void public function testEach(): void { DependencyHelper::map('From --> To, ToAnother')->each(function (Dependency $from, Dependency $to) { - assertTrue($from->equals(new Clazz('From'))); + $this->assertTrue($from->equals(new Clazz('From'))); }); } public function testReduce(): void { $dependencies = DependencyHelper::map('From --> To, ToAnother'); - assertEquals('ToToAnother', $dependencies->reduce('', function (string $output, Dependency $from, Dependency $to) { + $this->assertEquals('ToToAnother', $dependencies->reduce('', function (string $output, Dependency $from, Dependency $to) { return $output.$to->toString(); })); } @@ -85,19 +85,19 @@ public function testFromClasses(): void { $dependencies = DependencyHelper::map('From --> To, ToAnother'); $expected = (new DependencySet())->add(new Clazz('From')); - assertEquals($expected, $dependencies->fromDependencies()); + $this->assertEquals($expected, $dependencies->fromDependencies()); } public function testAllClasses(): void { $dependencies = DependencyHelper::map('From --> To, ToAnother'); $expected = DependencyHelper::dependencySet('From, To, ToAnother'); - assertEquals($expected, $dependencies->allDependencies()); + $this->assertEquals($expected, $dependencies->allDependencies()); } public function testToString(): void { - assertEquals( + $this->assertEquals( 'VendorA\\A --> VendorB\\A'.PHP_EOL .'VendorA\\A --> VendorA\\C'.PHP_EOL .'VendorB\\B --> VendorA\\A'.PHP_EOL @@ -112,7 +112,7 @@ public function testToString(): void public function testMapToArray(): void { - assertEquals([new Clazz('A'), new Clazz('C')], DependencyHelper::map(' + $this->assertEquals([new Clazz('A'), new Clazz('C')], DependencyHelper::map(' A --> B C --> D ')->mapToArray(function (Dependency $from, Dependency $to) { @@ -122,7 +122,7 @@ public function testMapToArray(): void public function testToArray(): void { - assertEquals([ + $this->assertEquals([ 'A' => [ 'key' => new Clazz('A'), 'value' => (new DependencySet())->add(new Clazz('B')), @@ -139,7 +139,7 @@ public function testToArray(): void public function testFilter(): void { - assertEquals( + $this->assertEquals( DependencyHelper::map('A --> B'), DependencyHelper::map(' A --> B @@ -152,7 +152,7 @@ public function testFilter(): void public function testCount(): void { - assertCount(2, DependencyHelper::map(' + $this->assertCount(2, DependencyHelper::map(' A --> B, C, D D --> E ')); @@ -168,12 +168,12 @@ public function testEquals(): void A --> B, C, D D --> E ')->add(new Clazz('D'), new Clazz('E')); - assertTrue($one->equals($two)); + $this->assertTrue($one->equals($two)); } public function testContainsIsTrueIfItMatchesTheKey(): void { - assertTrue(DependencyHelper::map(' + $this->assertTrue(DependencyHelper::map(' A --> B, C, D D --> E ')->contains(new Clazz('A'))); @@ -181,7 +181,7 @@ public function testContainsIsTrueIfItMatchesTheKey(): void public function testContainsIsFalseIfItOnlyMatchesTheValue(): void { - assertFalse(DependencyHelper::map(' + $this->assertFalse(DependencyHelper::map(' A --> B, C, D D --> E ')->contains(new Clazz('E'))); @@ -193,14 +193,14 @@ public function testMapAllDependencies(): void A\b --> C Y --> Z\d '); - assertEquals(DependencyHelper::dependencySet('_A, _Z'), $map->mapAllDependencies(function (Dependency $dependency) { + $this->assertEquals(DependencyHelper::dependencySet('_A, _Z'), $map->mapAllDependencies(function (Dependency $dependency) { return $dependency->namespaze(); })); } public function testGet(): void { - assertEquals( + $this->assertEquals( DependencyHelper::dependencySet('A, B, C'), DependencyHelper::map('D --> A, B, C')->get(new Clazz('D')) ); @@ -208,7 +208,7 @@ public function testGet(): void public function testReduceEachDependency(): void { - assertEquals(DependencyHelper::map(' + $this->assertEquals(DependencyHelper::map(' _A --> _B, _C '), DependencyHelper::map(' A\b --> B\d, C\d @@ -221,28 +221,28 @@ public function testReduceEachDependency(): void public function testDoesNotPrintNullDependenciesInKey(): void { $map = (new DependencyMap())->add(new NullDependency(), new Clazz('A')); - assertEmpty($map->toString()); + $this->assertEmpty($map->toString()); } public function testDoesNotPrintNullDependenciesInValue(): void { $map = (new DependencyMap())->add(new Clazz('A'), new NullDependency()); - assertEmpty($map->toString()); + $this->assertEmpty($map->toString()); } public function testCannotAddEmptyNamespaceAsFrom(): void { - assertEmpty((new DependencyMap())->add(new Clazz('A'), new Namespaze([]))); + $this->assertEmpty((new DependencyMap())->add(new Clazz('A'), new Namespaze([]))); } public function testCannotAddEmptyNamespaceAsTo(): void { - assertEmpty((new DependencyMap())->add(new Namespaze([]), new Clazz('A'))); + $this->assertEmpty((new DependencyMap())->add(new Namespaze([]), new Clazz('A'))); } public function testCannotAddSelf(): void { - assertEmpty((new DependencyMap())->add(new Clazz('A'), new Clazz('self'))); + $this->assertEmpty((new DependencyMap())->add(new Clazz('A'), new Clazz('self'))); } public function testCannotAddDependencyToYourself(): void @@ -256,6 +256,6 @@ public function testCannotAddDependencyToYourself(): void new Clazz('A'), new Clazz('static') ); - assertEmpty($dependencyMap); + $this->assertEmpty($dependencyMap); } } diff --git a/tests/unit/Dependencies/DependencySetTest.php b/tests/unit/Dependencies/DependencySetTest.php index 573dcb3..d2ec993 100644 --- a/tests/unit/Dependencies/DependencySetTest.php +++ b/tests/unit/Dependencies/DependencySetTest.php @@ -18,7 +18,7 @@ public function testAdd(): void $clazzCollection = (new DependencySet()) ->add(new Clazz('Test')); $clazzCollection->each(function (Dependency $clazz) { - assertEquals(new Clazz('Test'), $clazz); + $this->assertEquals(new Clazz('Test'), $clazz); }); } @@ -27,21 +27,21 @@ public function testIsImmutable(): void $clazzCollection = (new DependencySet()) ->add(new Clazz('Test')); $newCollectionAfterRefusingDuplicate = $clazzCollection->add(new Clazz('Test')); - assertNotSame($clazzCollection, $newCollectionAfterRefusingDuplicate); + $this->assertNotSame($clazzCollection, $newCollectionAfterRefusingDuplicate); } public function testDoesNotAcceptDuplicates(): void { $clazzCollection = (new DependencySet()) ->add(new Clazz('Test')); - assertEquals($clazzCollection, $clazzCollection->add(new Clazz('Test'))); + $this->assertEquals($clazzCollection, $clazzCollection->add(new Clazz('Test'))); } public function testToArray(): void { $clazzCollection = (new DependencySet()) ->add(new Clazz('Test')); - assertEquals([new Clazz('Test')], $clazzCollection->toArray()); + $this->assertEquals([new Clazz('Test')], $clazzCollection->toArray()); } public function testToString(): void @@ -49,34 +49,34 @@ public function testToString(): void $clazzCollection = (new DependencySet()) ->add(new Clazz('Test')) ->add(new Clazz('Test2')); - assertEquals('Test'.PHP_EOL.'Test2', $clazzCollection->__toString()); + $this->assertEquals('Test'.PHP_EOL.'Test2', $clazzCollection->__toString()); } public function testFilter(): void { $expected = DependencyHelper::dependencySet('AB, AC'); - assertEquals($expected, DependencyHelper::dependencySet('AB, AC, BA, CA')->filter(function (Dependency $dependency) { + $this->assertEquals($expected, DependencyHelper::dependencySet('AB, AC, BA, CA')->filter(function (Dependency $dependency) { return strpos($dependency->toString(), 'A') === 0; })); } public function testReduce(): void { - assertEquals('ABC', DependencyHelper::dependencySet('A, B, C')->reduce('', function (string $carry, Dependency $dependency) { + $this->assertEquals('ABC', DependencyHelper::dependencySet('A, B, C')->reduce('', function (string $carry, Dependency $dependency) { return $carry.$dependency->toString(); })); } public function testNoneIsTrueWhenNoneMatches(): void { - assertTrue(DependencyHelper::dependencySet('AB, AC, BA, CA')->none(function (Dependency $dependency) { + $this->assertTrue(DependencyHelper::dependencySet('AB, AC, BA, CA')->none(function (Dependency $dependency) { return strpos($dependency->toString(), 'D') === 0; })); } public function testNoneIsFalseWhenSomeMatch(): void { - assertFalse(DependencyHelper::dependencySet('AB, AC, BA, CA')->none(function (Dependency $dependency) { + $this->assertFalse(DependencyHelper::dependencySet('AB, AC, BA, CA')->none(function (Dependency $dependency) { return strpos($dependency->toString(), 'A') === 0; })); } diff --git a/tests/unit/Dependencies/NamespazeTest.php b/tests/unit/Dependencies/NamespazeTest.php index 09b4e41..52fa4f6 100644 --- a/tests/unit/Dependencies/NamespazeTest.php +++ b/tests/unit/Dependencies/NamespazeTest.php @@ -14,12 +14,12 @@ class NamespazeTest extends TestCase { public function testAcceptsEmptyNamespace(): void { - assertEquals('', new Namespaze([])); + $this->assertEquals('', new Namespaze([])); } public function testAcceptsValidNamespaceParts(): void { - assertEquals('a\b\c', new Namespaze(['a', 'b', 'c'])); + $this->assertEquals('a\b\c', new Namespaze(['a', 'b', 'c'])); } public function testDetectsInvalidNamespaceParts(): void @@ -30,78 +30,78 @@ public function testDetectsInvalidNamespaceParts(): void public function testDepthOfEmptyNamespaceIsZero(): void { - assertCount(0, new Namespaze([])); + $this->assertCount(0, new Namespaze([])); } public function testDepthOfNamespace(): void { - assertCount(2, new Namespaze(['A', 'B'])); + $this->assertCount(2, new Namespaze(['A', 'B'])); } public function testReducingDepthLowerThanPossibleProducesNullDependency(): void { - assertInstanceOf(NullDependency::class, (new Namespaze(['Test']))->reduceToDepth(3)); + $this->assertInstanceOf(NullDependency::class, (new Namespaze(['Test']))->reduceToDepth(3)); } public function testReduceToMaxDepth(): void { - assertEquals(new Namespaze(['A', 'B']), (new Namespaze(['A', 'B', 'C', 'D']))->reduceToDepth(2)); + $this->assertEquals(new Namespaze(['A', 'B']), (new Namespaze(['A', 'B', 'C', 'D']))->reduceToDepth(2)); } public function testDoNotReduceForMaxDepthZero(): void { - assertEquals(new Namespaze(['A', 'B']), (new Namespaze(['A', 'B']))->reduceToDepth(0)); + $this->assertEquals(new Namespaze(['A', 'B']), (new Namespaze(['A', 'B']))->reduceToDepth(0)); } public function testLeftReduceNamespace(): void { - assertEquals(new Namespaze(['C']), (new Namespaze(['A', 'B', 'C']))->reduceDepthFromLeftBy(2)); + $this->assertEquals(new Namespaze(['C']), (new Namespaze(['A', 'B', 'C']))->reduceDepthFromLeftBy(2)); } public function testReduceSameAsLengthProducesEmptyNamespace(): void { - assertEquals(new Namespaze([]), (new Namespaze(['A', 'B', 'C']))->reduceDepthFromLeftBy(3)); + $this->assertEquals(new Namespaze([]), (new Namespaze(['A', 'B', 'C']))->reduceDepthFromLeftBy(3)); } public function testReduceMoreThanLengthProducesEmptyNamespace(): void { - assertEquals(new Namespaze([]), (new Namespaze(['A', 'B', 'C']))->reduceDepthFromLeftBy(5)); + $this->assertEquals(new Namespaze([]), (new Namespaze(['A', 'B', 'C']))->reduceDepthFromLeftBy(5)); } public function testEquals(): void { - assertTrue((new Namespaze(['A', 'B']))->equals(new Namespaze(['A', 'B']))); - assertTrue((new Namespaze([]))->equals(new Namespaze([]))); - assertFalse((new Namespaze(['A', 'B']))->equals(new Namespaze(['A']))); - assertFalse((new Namespaze(['A', 'B']))->equals(new Namespaze([]))); + $this->assertTrue((new Namespaze(['A', 'B']))->equals(new Namespaze(['A', 'B']))); + $this->assertTrue((new Namespaze([]))->equals(new Namespaze([]))); + $this->assertFalse((new Namespaze(['A', 'B']))->equals(new Namespaze(['A']))); + $this->assertFalse((new Namespaze(['A', 'B']))->equals(new Namespaze([]))); } public function testPartsByIndex(): void { - assertEquals(new Namespaze(['1']), (new Namespaze(['1', '2']))->parts()[0]); - assertEquals(new Namespaze(['2']), (new Namespaze(['1', '2']))->parts()[1]); + $this->assertEquals(new Namespaze(['1']), (new Namespaze(['1', '2']))->parts()[0]); + $this->assertEquals(new Namespaze(['2']), (new Namespaze(['1', '2']))->parts()[1]); } public function testNamespazeReturnsItself(): void { - assertEquals(new Namespaze(['1', '2']), (new Namespaze(['1', '2']))->namespaze()); + $this->assertEquals(new Namespaze(['1', '2']), (new Namespaze(['1', '2']))->namespaze()); } public function testDetectsIfInOtherNamespace(): void { - assertTrue((new Namespaze(['A', 'b', 'T']))->inNamespaze(new Namespaze(['A', 'b', 'T']))); - assertTrue((new Namespaze(['A', 'b', 'T']))->inNamespaze(new Namespaze(['A']))); + $this->assertTrue((new Namespaze(['A', 'b', 'T']))->inNamespaze(new Namespaze(['A', 'b', 'T']))); + $this->assertTrue((new Namespaze(['A', 'b', 'T']))->inNamespaze(new Namespaze(['A']))); } public function testDetectsIfNotInOtherNamespace(): void { - assertFalse((new Namespaze(['XZY', 'b', 'T']))->inNamespaze(new Namespaze(['A', 'b', 'T']))); - assertFalse((new Namespaze([]))->inNamespaze(new Namespaze(['A', 'b', 'T']))); - assertFalse((new Namespaze(['XZY', 'b', 'T']))->inNamespaze(new Namespaze([]))); + $this->assertFalse((new Namespaze(['XZY', 'b', 'T']))->inNamespaze(new Namespaze(['A', 'b', 'T']))); + $this->assertFalse((new Namespaze([]))->inNamespaze(new Namespaze(['A', 'b', 'T']))); + $this->assertFalse((new Namespaze(['XZY', 'b', 'T']))->inNamespaze(new Namespaze([]))); } public function testEmptyNamespaceIsNotNamespaced(): void { - assertFalse((new Namespaze([]))->isNamespaced()); + $this->assertFalse((new Namespaze([]))->isNamespaced()); } } diff --git a/tests/unit/Dependencies/NullDependencyTest.php b/tests/unit/Dependencies/NullDependencyTest.php index dc60cc7..1330fcf 100644 --- a/tests/unit/Dependencies/NullDependencyTest.php +++ b/tests/unit/Dependencies/NullDependencyTest.php @@ -13,46 +13,46 @@ class NullDependencyTest extends TestCase { public function testReduceToDepth(): void { - assertEquals(new NullDependency(), (new NullDependency())->reduceToDepth(99)); + $this->assertEquals(new NullDependency(), (new NullDependency())->reduceToDepth(99)); } public function testReduceDepthFromLeftBy(): void { - assertEquals(new NullDependency(), (new NullDependency())->reduceDepthFromLeftBy(99)); + $this->assertEquals(new NullDependency(), (new NullDependency())->reduceDepthFromLeftBy(99)); } public function testEquals(): void { - assertFalse((new NullDependency())->equals(new NullDependency())); + $this->assertFalse((new NullDependency())->equals(new NullDependency())); } public function testToString(): void { - assertEquals('', (new NullDependency())->__toString()); + $this->assertEquals('', (new NullDependency())->__toString()); } public function testNamespaze(): void { - assertEquals(new Namespaze([]), (new NullDependency())->namespaze()); + $this->assertEquals(new Namespaze([]), (new NullDependency())->namespaze()); } public function testInNamespazeIsFalseForEmptyNamespace(): void { - assertFalse((new NullDependency())->inNamespaze(new Namespaze([]))); + $this->assertFalse((new NullDependency())->inNamespaze(new Namespaze([]))); } public function testInNamespazeIsFalseForEveryNamespace(): void { - assertFalse((new NullDependency())->inNamespaze(new Namespaze(['A']))); + $this->assertFalse((new NullDependency())->inNamespaze(new Namespaze(['A']))); } public function testCountIsAlwaysZero(): void { - assertCount(0, new NullDependency()); + $this->assertCount(0, new NullDependency()); } public function testIsNotNamespaced(): void { - assertFalse((new NullDependency())->isNamespaced()); + $this->assertFalse((new NullDependency())->isNamespaced()); } } diff --git a/tests/unit/DependencyHelper.php b/tests/unit/DependencyHelper.php index 29b1b3d..8aa9829 100644 --- a/tests/unit/DependencyHelper.php +++ b/tests/unit/DependencyHelper.php @@ -27,7 +27,7 @@ class DependencyHelper * * @throws InvalidArgumentException */ - public static function map(string $input) : DependencyMap + public static function map(string $input): DependencyMap { $lines = preg_split('/\v+/', $input, -1, PREG_SPLIT_NO_EMPTY); $array_reduce = array_reduce( @@ -59,7 +59,7 @@ public static function clazz(string $input): Dependency * * @return Namespaze */ - public static function namespaze(string $input) : Namespaze + public static function namespaze(string $input): Namespaze { return new Namespaze(explode('\\', $input)); } @@ -69,7 +69,7 @@ public static function namespaze(string $input) : Namespaze * * @return array */ - public static function dependencyPair(string $input) : array + public static function dependencyPair(string $input): array { $tokens = explode('-->', str_replace(' ', '', $input)); return [self::dependency($tokens[0]), self::dependencySet($tokens[1])]; @@ -80,7 +80,7 @@ public static function dependencyPair(string $input) : array * * @return DependencySet */ - public static function dependencySet(string $input) : DependencySet + public static function dependencySet(string $input): DependencySet { $set = new DependencySet(); if ($input === '_') { @@ -93,7 +93,7 @@ public static function dependencySet(string $input) : DependencySet return $set; } - private static function dependency(string $input) : Dependency + private static function dependency(string $input): Dependency { $input = str_replace(' ', '', $input); if (strpos($input, '_') === 0) { diff --git a/tests/unit/DependencyHelperTest.php b/tests/unit/DependencyHelperTest.php index 7c202b9..13d9107 100644 --- a/tests/unit/DependencyHelperTest.php +++ b/tests/unit/DependencyHelperTest.php @@ -24,7 +24,7 @@ public function testConvert(): void new Clazz('DepC', new Namespaze(['C'])), new Clazz('DepD', new Namespaze(['D'])) ); - assertEquals($expected, DependencyHelper::map(' + $this->assertEquals($expected, DependencyHelper::map(' A\\DepA --> B\\DepB C\\DepC --> D\\DepD ')); @@ -39,7 +39,7 @@ public function testConvertMultipleDependencies(): void new Clazz('DepA', new Namespaze(['A'])), new Clazz('DepD', new Namespaze(['D'])) ); - assertEquals($expected, DependencyHelper::map(' + $this->assertEquals($expected, DependencyHelper::map(' A\\DepA --> B\\DepB, D\\DepD ')); } diff --git a/tests/unit/Formatters/DependencyStructureMatrixBuilderTest.php b/tests/unit/Formatters/DependencyStructureMatrixBuilderTest.php index 93cf730..7a89196 100644 --- a/tests/unit/Formatters/DependencyStructureMatrixBuilderTest.php +++ b/tests/unit/Formatters/DependencyStructureMatrixBuilderTest.php @@ -1,4 +1,6 @@ - A D --> B '); - assertEquals([ + $this->assertEquals([ 'A' => ['A' => 0, 'B' => 0, 'C' => 1, 'D' => 0], 'B' => ['A' => 1, 'B' => 0, 'C' => 0, 'D' => 1], 'C' => ['A' => 0, 'B' => 0, 'C' => 0, 'D' => 0], @@ -43,7 +45,7 @@ public function testBuildMatrixFromClassesWithNamespaces(): void CC\\C --> AA\\A DD\\D --> BB\\B '); - assertEquals([ + $this->assertEquals([ 'AA\\A' => ['AA\\A' => 0, 'BB\\B' => 0, 'CC\\C' => 1, 'DD\\D' => 0], 'BB\\B' => ['AA\\A' => 1, 'BB\\B' => 0, 'CC\\C' => 0, 'DD\\D' => 1], 'CC\\C' => ['AA\\A' => 0, 'BB\\B' => 0, 'CC\\C' => 0, 'DD\\D' => 0], diff --git a/tests/unit/Formatters/DotFormatterTest.php b/tests/unit/Formatters/DotFormatterTest.php index 5c9b2b8..e0b8a42 100644 --- a/tests/unit/Formatters/DotFormatterTest.php +++ b/tests/unit/Formatters/DotFormatterTest.php @@ -1,4 +1,6 @@ -format(DependencyHelper::map(' + $this->assertEquals($expected, (new DotFormatter())->format(DependencyHelper::map(' A --> B C --> D A\\b --> D\\c diff --git a/tests/unit/Formatters/PlantUmlFormatterTest.php b/tests/unit/Formatters/PlantUmlFormatterTest.php index 7d155e7..9f95c9e 100644 --- a/tests/unit/Formatters/PlantUmlFormatterTest.php +++ b/tests/unit/Formatters/PlantUmlFormatterTest.php @@ -23,7 +23,7 @@ protected function setUp(): void public function testFormat(): void { $dependencyCollection = DependencyHelper::map('ClassA --> ClassB, ClassC'); - assertEquals("@startuml\n\n" + $this->assertEquals("@startuml\n\n" ."ClassA --|> ClassB\n" ."ClassA --|> ClassC\n" .'@enduml', $this->plantUmlFormatter->format($dependencyCollection)); @@ -31,7 +31,7 @@ public function testFormat(): void public function testFormatsNestedNamespaces(): void { - assertEquals('@startuml + $this->assertEquals('@startuml namespace A { namespace b { } diff --git a/tests/unit/OS/DotWrapperTest.php b/tests/unit/OS/DotWrapperTest.php index 9844f07..caa0b2e 100644 --- a/tests/unit/OS/DotWrapperTest.php +++ b/tests/unit/OS/DotWrapperTest.php @@ -1,4 +1,6 @@ -url(); $this->shellWrapper - ->expects(exactly(2)) + ->expects($this->exactly(2)) ->method('run') ->withConsecutive( ['dot -V'], @@ -59,9 +61,9 @@ public function testKeepsDotFiles(): void { $root = vfsStream::setup()->url(); $testFile = new SplFileInfo($root.'/test'); - assertFileNotExists($testFile->getPathname()); + $this->assertFileDoesNotExist($testFile->getPathname()); $this->dotWrapper->generate(new DependencyMap(), new SplFileInfo($testFile->getPathname()), true); - assertFileExists($testFile->getPathname()); + $this->assertFileExists($testFile->getPathname()); } @@ -70,6 +72,6 @@ public function testRemovesDotFiles(): void $root = vfsStream::setup()->url(); $testFile = new SplFileInfo($root.'/test'); $this->dotWrapper->generate(new DependencyMap(), new SplFileInfo($root.'/test.png'), false); - assertFileNotExists($testFile->getPathname()); + $this->assertFileDoesNotExist($testFile->getPathname()); } } diff --git a/tests/unit/OS/PhpFileFinderTest.php b/tests/unit/OS/PhpFileFinderTest.php index 32174ea..e77423a 100644 --- a/tests/unit/OS/PhpFileFinderTest.php +++ b/tests/unit/OS/PhpFileFinderTest.php @@ -31,7 +31,7 @@ public function testFindsSingleFileInFlatStructure(): void $dir = new SplFileInfo($mockDir->url()); $expected = (new PhpFileSet()) ->add(new PhpFile(new SplFileInfo($mockDir->url().'/root/someFile.php'))); - assertEquals($expected, $this->finder->find($dir)); + $this->assertEquals($expected, $this->finder->find($dir)); } public function testFindsFilesInDeepStructure(): void @@ -58,7 +58,7 @@ public function testFindsFilesInDeepStructure(): void ->add(new PhpFile(new SplFileInfo($mockDir->url().'/root/dirA/dirB/fileInB.php'))) ->add(new PhpFile(new SplFileInfo($mockDir->url().'/root/dirA/dirB/fileInB2.php'))) ->add(new PhpFile(new SplFileInfo($mockDir->url().'/root/dirA/dirB/dirC/fileInC.php'))); - assertEquals($expected, $this->finder->find($dir)); + $this->assertEquals($expected, $this->finder->find($dir)); } public function testFindsNothingIfThereIsNothing(): void @@ -79,7 +79,7 @@ public function testFindsNothingIfThereIsNothing(): void ], ]); $dir = new SplFileInfo($mockDir->url()); - assertEmpty($this->finder->find($dir)); + $this->assertEmpty($this->finder->find($dir)); } public function testFindFilesInDeeplyNestedDirectory(): void @@ -108,6 +108,6 @@ public function testFindFilesInDeeplyNestedDirectory(): void $mockDir->url().'/root/dirA', $mockDir->url().'/root/dirB', ]); - assertEquals($expected, $actual); + $this->assertEquals($expected, $actual); } } diff --git a/tests/unit/OS/PhpFileSetTest.php b/tests/unit/OS/PhpFileSetTest.php index 78bff0a..b269cdd 100644 --- a/tests/unit/OS/PhpFileSetTest.php +++ b/tests/unit/OS/PhpFileSetTest.php @@ -20,7 +20,7 @@ public function testEquals(): void ->add($file); $collection2 = (new PhpFileSet()) ->add($file); - assertTrue($collection1->equals($collection2)); + $this->assertTrue($collection1->equals($collection2)); } public function testDoesNotAllowDuplicated(): void @@ -28,7 +28,7 @@ public function testDoesNotAllowDuplicated(): void $set = (new PhpFileSet()) ->add(new PhpFile(new SplFileInfo(__DIR__))) ->add(new PhpFile(new SplFileInfo(__DIR__))); - assertCount(1, $set); + $this->assertCount(1, $set); } public function testIsImmutable(): void @@ -36,7 +36,7 @@ public function testIsImmutable(): void $set = (new PhpFileSet()) ->add(new PhpFile(new SplFileInfo(__DIR__))); $setAfterRefusingDuplicate = $set->add(new PhpFile(new SplFileInfo(__DIR__))); - assertNotSame($set, $setAfterRefusingDuplicate); + $this->assertNotSame($set, $setAfterRefusingDuplicate); } public function testNotEquals(): void @@ -45,18 +45,18 @@ public function testNotEquals(): void ->add(new PhpFile(new SplFileInfo(sys_get_temp_dir()))); $collection2 = (new PhpFileSet()) ->add(new PhpFile(new SplFileInfo(__DIR__))); - assertFalse($collection1->equals($collection2)); + $this->assertFalse($collection1->equals($collection2)); } public function testCount0WhenEmpty(): void { $collection1 = new PhpFileSet(); - assertCount(0, $collection1); + $this->assertCount(0, $collection1); } public function testCount(): void { - assertCount(2, (new PhpFileSet()) + $this->assertCount(2, (new PhpFileSet()) ->add(new PhpFile(new SplFileInfo(__DIR__))) ->add(new PhpFile(new SplFileInfo(__DIR__.'/../../../composer.json')))); } @@ -65,7 +65,7 @@ public function testEach(): void { $collection1 = (new PhpFileSet())->add(new PhpFile(new SplFileInfo(__DIR__))); $collection1->each(function (PhpFile $file) { - assertEquals(new PhpFile(new SplFileInfo(__DIR__)), $file); + $this->assertEquals(new PhpFile(new SplFileInfo(__DIR__)), $file); }); } @@ -75,8 +75,8 @@ public function testMapToArray(): void ->add(new PhpFile(new SplFileInfo(__DIR__))) ->add(new PhpFile(new SplFileInfo(__FILE__))) ->toArray(); - assertEquals(new PhpFile(new SplFileInfo(__DIR__)), $collection1[0]); - assertEquals(new PhpFile(new SplFileInfo(__DIR__)), $collection1[1]); + $this->assertEquals(new PhpFile(new SplFileInfo(__DIR__)), $collection1[0]); + $this->assertEquals(new PhpFile(new SplFileInfo(__DIR__)), $collection1[1]); } public function testAddAll(): void @@ -86,8 +86,8 @@ public function testAddAll(): void ->add(new PhpFile(new SplFileInfo(__DIR__))) ->add(new PhpFile(new SplFileInfo(__FILE__))); $combinedCollection = $collection1->addAll($collection2)->toArray(); - assertCount(2, $combinedCollection); - assertEquals(new PhpFile(new SplFileInfo(__DIR__)), $combinedCollection[0]); - assertEquals(new PhpFile(new SplFileInfo(__FILE__)), $combinedCollection[1]); + $this->assertCount(2, $combinedCollection); + $this->assertEquals(new PhpFile(new SplFileInfo(__DIR__)), $combinedCollection[0]); + $this->assertEquals(new PhpFile(new SplFileInfo(__FILE__)), $combinedCollection[1]); } } diff --git a/tests/unit/OS/PhpFileTest.php b/tests/unit/OS/PhpFileTest.php index 3d1e069..fb6a379 100644 --- a/tests/unit/OS/PhpFileTest.php +++ b/tests/unit/OS/PhpFileTest.php @@ -22,14 +22,14 @@ public function testEquals(): void { $file1 = new PhpFile(new SplFileInfo(sys_get_temp_dir())); $file2 = new PhpFile(new SplFileInfo(sys_get_temp_dir())); - assertTrue($file1->equals($file2)); + $this->assertTrue($file1->equals($file2)); } public function testNotEquals(): void { $file1 = new PhpFile(new SplFileInfo(sys_get_temp_dir())); $file2 = new PhpFile(new SplFileInfo(__DIR__)); - assertFalse($file1->equals($file2)); + $this->assertFalse($file1->equals($file2)); } public function testReturnsCode(): void @@ -39,7 +39,7 @@ public function testReturnsCode(): void 'someFile.php' => $code, ]); $file = new PhpFile(new SplFileInfo($mockDir->url().'/someFile.php')); - assertEquals($code, $file->code()); + $this->assertEquals($code, $file->code()); } public function testToString(): void diff --git a/tests/unit/OS/PlantUmlWrapperTest.php b/tests/unit/OS/PlantUmlWrapperTest.php index b32db55..b98e61b 100644 --- a/tests/unit/OS/PlantUmlWrapperTest.php +++ b/tests/unit/OS/PlantUmlWrapperTest.php @@ -41,14 +41,14 @@ public function testDetectsIfPlantUmlIsNotInstalled(): void public function testDetectsIfPlantUmlIsInstalled(): void { $this->shellWrapper->method('run')->willReturn(0); - assertInstanceOf(PlantUmlWrapper::class, new PlantUmlWrapper($this->plantUmlFormatter, $this->shellWrapper)); + $this->assertInstanceOf(PlantUmlWrapper::class, new PlantUmlWrapper($this->plantUmlFormatter, $this->shellWrapper)); } public function testGenerate(): void { $plantUml = new PlantUmlWrapper($this->plantUmlFormatter, $this->shellWrapper); $plantUml->generate(new DependencyMap(), new SplFileInfo(sys_get_temp_dir().'/dependencies.png'), true); - assertFileExists(sys_get_temp_dir().'/dependencies.uml'); + $this->assertFileExists(sys_get_temp_dir().'/dependencies.uml'); unlink(sys_get_temp_dir().'/dependencies.uml'); } @@ -56,6 +56,6 @@ public function testRemoveUml(): void { $plantUml = new PlantUmlWrapper($this->plantUmlFormatter, $this->shellWrapper); $plantUml->generate(new DependencyMap(), new SplFileInfo(sys_get_temp_dir().'/dependencies.png')); - assertFileNotExists(sys_get_temp_dir().'/dependencies.uml'); + $this->assertFileDoesNotExist(sys_get_temp_dir().'/dependencies.uml'); } } diff --git a/tests/unit/OS/ShellWrapperTest.php b/tests/unit/OS/ShellWrapperTest.php index e8f05d6..7a5bab4 100644 --- a/tests/unit/OS/ShellWrapperTest.php +++ b/tests/unit/OS/ShellWrapperTest.php @@ -16,11 +16,11 @@ class ShellWrapperTest extends TestCase */ public function testDetectsEcho(): void { - assertEquals(0, (new ShellWrapper())->run('echo')); + $this->assertEquals(0, (new ShellWrapper())->run('echo')); } public function testDetectsWhenApplicationNotInstalled(): void { - assertNotEquals(0, (new ShellWrapper())->run('xjcsajhckjsdfhksdf')); + $this->assertNotEquals(0, (new ShellWrapper())->run('xjcsajhckjsdfhksdf')); } } diff --git a/tests/unit/Util/DependencyContainerTest.php b/tests/unit/Util/DependencyContainerTest.php index ae23367..c73b9a6 100644 --- a/tests/unit/Util/DependencyContainerTest.php +++ b/tests/unit/Util/DependencyContainerTest.php @@ -25,7 +25,7 @@ public function provideMethods(): array if (!$method->hasReturnType()) { continue; } - $methods[] = [$method->getName(), (string) $method->getReturnType()]; + $methods[] = [$method->getName(), $method->getReturnType()->getName()]; } return $methods; } @@ -37,6 +37,6 @@ public function provideMethods(): array */ public function testCanInstantiateAllDependencies(string $methodName, string $expectedReturnType): void { - assertInstanceOf($expectedReturnType, (new DependencyContainer([]))->{$methodName}()); + $this->assertInstanceOf($expectedReturnType, (new DependencyContainer([]))->{$methodName}()); } } diff --git a/tests/unit/Util/FunctionalTest.php b/tests/unit/Util/FunctionalTest.php index 66d330e..56d8d56 100644 --- a/tests/unit/Util/FunctionalTest.php +++ b/tests/unit/Util/FunctionalTest.php @@ -19,7 +19,7 @@ public function testCompose(): void $multiplyByTwo = function ($x) { return $x * 2; }; - assertEquals(8, Functional::compose( + $this->assertEquals(8, Functional::compose( $incrementByOne, $multiplyByTwo, $multiplyByTwo @@ -28,6 +28,6 @@ public function testCompose(): void public function testComposeWithoutArgumentsReturnsId(): void { - assertEquals(9, Functional::compose()(9)); + $this->assertEquals(9, Functional::compose()(9)); } } diff --git a/tests/unit/Util/UtilTest.php b/tests/unit/Util/UtilTest.php index 4f04b7d..750c943 100644 --- a/tests/unit/Util/UtilTest.php +++ b/tests/unit/Util/UtilTest.php @@ -13,28 +13,28 @@ class UtilTest extends TestCase { public function testArrayMatchesAtLeastOnce(): void { - assertTrue(Util::array_once([1, 2, 3, 'tt'], function ($value, $index) { + $this->assertTrue(Util::array_once([1, 2, 3, 'tt'], function ($value, $index) { return $value === 'tt'; })); } public function testArrayMatchesIndex(): void { - assertTrue(Util::array_once([1, 2, 3, 'tt'], function ($value, $index) { + $this->assertTrue(Util::array_once([1, 2, 3, 'tt'], function ($value, $index) { return $index === 3 && $value === 'tt'; })); } public function testArrayMatchesNothing(): void { - assertFalse(Util::array_once([1, 2, 3, 'tt'], function ($value, $index) { + $this->assertFalse(Util::array_once([1, 2, 3, 'tt'], function ($value, $index) { return $value === 'xxx'; })); } public function testReduceArrayWithKeys(): void { - assertEquals('0a1b2c3d', Util::reduce(['a', 'b', 'c', 'd'], function (string $carry, int $index, string $value) { + $this->assertEquals('0a1b2c3d', Util::reduce(['a', 'b', 'c', 'd'], function (string $carry, int $index, string $value) { return $carry.$index.$value; }, '')); }