Skip to content

Commit

Permalink
Moooaare tests
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Nov 16, 2023
1 parent c889462 commit 636f99e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 33 deletions.
6 changes: 3 additions & 3 deletions src/Lens/Lens.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down
11 changes: 1 addition & 10 deletions src/Reflect/Internal/reflect_object.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 0 additions & 2 deletions tests/unit/Lens/ComposeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Lens/LensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}


Expand Down
5 changes: 2 additions & 3 deletions tests/unit/Reflect/InstantiateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down
21 changes: 7 additions & 14 deletions tests/unit/Reflect/Internal/ReflectObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,27 @@

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());

static::assertInstanceOf(ReflectionObject::class, $rc);
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());
}
}

0 comments on commit 636f99e

Please sign in to comment.