Skip to content

Commit

Permalink
Add testUnserializableRootObject
Browse files Browse the repository at this point in the history
  • Loading branch information
koriym committed Apr 21, 2023
1 parent ead91fd commit 27900ae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
29 changes: 29 additions & 0 deletions tests/Fake/fake-app/src/Module/BadModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace FakeVendor\HelloWorld\Module;

use BEAR\Sunday\Extension\Error\ThrowableHandlerInterface;
use BEAR\Sunday\Extension\Router\RouterMatch;
use Ray\Di\AbstractModule;
use Throwable;

class BadModule extends AbstractModule
{
/**
* {@inheritdoc}
*/
protected function configure(): void
{
// Invalid. You can not to bind unserializable object.
$this->bind(ThrowableHandlerInterface::class)->toInstance(new class implements ThrowableHandlerInterface {
public function handle(Throwable $e, RouterMatch $request): ThrowableHandlerInterface
{
}
public function transfer(): void
{
}
});
}
}
4 changes: 2 additions & 2 deletions tests/Injector/PackageInjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ protected function configure(): void
$this->assertInstanceOf(FakeDep2::class, $page->foo);
}

public function testWithNullCacheWarning(): void
public function testUnserializableRootObject(): void
{
set_error_handler(static function (int $errno, string $errstr): void {
throw new Exception($errstr, $errno);
}, E_USER_WARNING);
$this->expectExceptionMessage('Failed to verify the injector cache.');
$injector = PackageInjector::getInstance(new Meta('FakeVendor\HelloWorld'), 'app', new NullAdapter());
$injector = PackageInjector::getInstance(new Meta('FakeVendor\HelloWorld'), 'bad-app', new NullAdapter());
$this->assertInstanceOf(InjectorInterface::class, $injector);
restore_error_handler();
}
Expand Down

0 comments on commit 27900ae

Please # to comment.