/
qK1e
/
php-method-overloading
Обзор
Документация
Войти
/
qK1e
/
php-method-overloading
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
tests/Comparators/BasicComparatorTest.php
78 строк
2 KB
Pavlovich
Renamed PassedArgument folder to Comparators
25 май 2024, 23:58
25 май 2024, 23:58
6fda441
Код
Авторство
О чём код?
<?php namespace Comparators; use PHPUnit\Framework\TestCase; use qK1e\Overloading\Comparators\BasicComparator; use ReflectionFunction; use ReflectionNamedType; class BasicComparatorTest extends TestCase { public function testInt() { $sut = new BasicComparator(1); $this->assertTrue($sut->sameType($this->int())); $this->assertFalse($sut->sameType($this->float())); $this->assertFalse($sut->sameType($this->string())); $this->assertFalse($sut->sameType($this->bool())); } public function testString() { $sut = new BasicComparator("1"); $this->assertFalse($sut->sameType($this->int())); $this->assertFalse($sut->sameType($this->float())); $this->assertTrue($sut->sameType($this->string())); $this->assertFalse($sut->sameType($this->bool())); } public function testFloat() { $sut = new BasicComparator(.1); $this->assertFalse($sut->sameType($this->int())); $this->assertTrue($sut->sameType($this->float())); $this->assertFalse($sut->sameType($this->string())); $this->assertFalse($sut->sameType($this->bool())); } public function testBool() { $sut = new BasicComparator(true); $this->assertFalse($sut->sameType($this->int())); $this->assertFalse($sut->sameType($this->float())); $this->assertFalse($sut->sameType($this->string())); $this->assertTrue($sut->sameType($this->bool())); } private function int(int $arg = 1): \ReflectionNamedType { return $this->getReflectionParams(__FUNCTION__); } private function float(float $arg = .1): ReflectionNamedType { return $this->getReflectionParams(__FUNCTION__); } private function string(string $arg = "1"): ReflectionNamedType { return $this->getReflectionParams(__FUNCTION__); } private function bool(bool $arg = true): ReflectionNamedType { return $this->getReflectionParams(__FUNCTION__); } private function getReflectionParams(string $functionName): ReflectionNamedType { $reflectionFunc = new ReflectionFunction($this->$functionName(...)); return $reflectionFunc->getParameters()[0]->getType(); } }