From 636f99e4a5e398f05ed4fcf16bb8160501049656 Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Thu, 16 Nov 2023 06:57:20 +0100 Subject: [PATCH] Moooaare tests --- src/Lens/Lens.php | 6 +++--- src/Reflect/Internal/reflect_object.php | 11 +--------- tests/unit/Lens/ComposeTest.php | 2 -- tests/unit/Lens/LensTest.php | 2 +- tests/unit/Reflect/InstantiateTest.php | 5 ++--- .../Reflect/Internal/ReflectObjectTest.php | 21 +++++++------------ 6 files changed, 14 insertions(+), 33 deletions(-) diff --git a/src/Lens/Lens.php b/src/Lens/Lens.php index 33a2aa1..34bd274 100644 --- a/src/Lens/Lens.php +++ b/src/Lens/Lens.php @@ -49,11 +49,11 @@ public static function identity(): self */ static fn ($s) => $s, /** - * @param I $s - * @param mixed $_ + * @param I $_ + * @param I $a * @returns I */ - static fn ($s, $_) => $s + static fn ($_, $a) => $a ); } diff --git a/src/Reflect/Internal/reflect_object.php b/src/Reflect/Internal/reflect_object.php index a96b120..16d6967 100644 --- a/src/Reflect/Internal/reflect_object.php +++ b/src/Reflect/Internal/reflect_object.php @@ -2,20 +2,11 @@ namespace VeeWee\Reflecta\Reflect; use ReflectionObject; -use Throwable; -use VeeWee\Reflecta\Reflect\Exception\UnreflectableException; /** * @psalm-internal VeeWee\Reflecta - * - * - * @throws UnreflectableException */ function reflect_object(object $object): ReflectionObject { - try { - return new ReflectionObject($object); - } catch (Throwable $previous) { - throw UnreflectableException::unknownClass(get_debug_type($object), $previous); - } + return new ReflectionObject($object); } diff --git a/tests/unit/Lens/ComposeTest.php b/tests/unit/Lens/ComposeTest.php index d49efa8..0822f14 100644 --- a/tests/unit/Lens/ComposeTest.php +++ b/tests/unit/Lens/ComposeTest.php @@ -11,8 +11,6 @@ final class ComposeTest extends TestCase { public function test_it_can_compose_lenses(): void { - static::markTestIncomplete('Identity doesnt seem to work as expected'); - $greetLens = index('greet'); $messageLens = index('message'); $composed = compose($greetLens, $messageLens); diff --git a/tests/unit/Lens/LensTest.php b/tests/unit/Lens/LensTest.php index 6c04599..499866d 100644 --- a/tests/unit/Lens/LensTest.php +++ b/tests/unit/Lens/LensTest.php @@ -61,7 +61,7 @@ public function test_it_can_have_identity(): void $lens = Lens::identity(); static::assertSame('hello', $lens->get('hello')); - static::assertSame('hello', $lens->set('hello', 'ignored')); + static::assertSame('hello', $lens->set('ignored', 'hello')); } diff --git a/tests/unit/Reflect/InstantiateTest.php b/tests/unit/Reflect/InstantiateTest.php index 554ed0d..18c2dbb 100644 --- a/tests/unit/Reflect/InstantiateTest.php +++ b/tests/unit/Reflect/InstantiateTest.php @@ -3,6 +3,7 @@ namespace VeeWee\Reflecta\UnitTests\Reflect; +use Generator; use PHPUnit\Framework\TestCase; use VeeWee\Reflecta\Reflect\Exception\UnreflectableException; use VeeWee\Reflecta\TestFixtures\Boom; @@ -12,12 +13,10 @@ final class InstantiateTest extends TestCase { - public function test_it_errors(): void { - static::markTestIncomplete('TODO : find final internal class'); $this->expectException(UnreflectableException::class); - instantiate('internalfinalclass'); + instantiate(Generator::class); } public function it_returns_instance() diff --git a/tests/unit/Reflect/Internal/ReflectObjectTest.php b/tests/unit/Reflect/Internal/ReflectObjectTest.php index 10f69fe..63164ea 100644 --- a/tests/unit/Reflect/Internal/ReflectObjectTest.php +++ b/tests/unit/Reflect/Internal/ReflectObjectTest.php @@ -5,22 +5,14 @@ use PHPUnit\Framework\TestCase; use ReflectionObject; -use VeeWee\Reflecta\Reflect\Exception\UnreflectableException; +use stdClass; use VeeWee\Reflecta\TestFixtures\X; use function VeeWee\Reflecta\Reflect\reflect_object; final class ReflectObjectTest extends TestCase { - - public function test_it_errors(): void - { - static::markTestIncomplete('TODO : find an unreflectable object'); - - $this->expectException(UnreflectableException::class); - reflect_object(null); - } - - public function it_returns_reflection_class() + + public function test_it_returns_reflection_class() { $rc = reflect_object(new X()); @@ -28,11 +20,12 @@ public function it_returns_reflection_class() static::assertSame(X::class, $rc->getName()); } - public function it_can_deal_with_stdClass() + + public function test_it_can_deal_with_std_class() { - $rc = reflect_object(new StdClass()); + $rc = reflect_object(new stdClass()); static::assertInstanceOf(ReflectionObject::class, $rc); - static::assertSame(StdClass::class, $rc->getName()); + static::assertSame(stdClass::class, $rc->getName()); } }