-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RemoteObjectFactoryTest.php
41 lines (34 loc) · 1.46 KB
/
RemoteObjectFactoryTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
* This file is part of the guanguans/laravel-proxy-manager.
*
* (c) guanguans <[email protected]>
*
* This source file is subject to the MIT license that is bundled.
*/
namespace Guanguans\LaravelProxyManagerTests\Facades;
use Guanguans\LaravelProxyManager\Facades\RemoteObjectFactory;
use Guanguans\LaravelProxyManagerTests\TestClasses\AbstractLocalBookObjectTestClass;
use Guanguans\LaravelProxyManagerTests\TestClasses\RemoteBookObjectAdapterTestClass;
use Guanguans\LaravelProxyManagerTests\TestClasses\RemoteBookObjectTestClass;
use Illuminate\Support\Facades\Route;
use ProxyManager\Proxy\RemoteObjectInterface;
beforeEach(function (): void {
Route::get('book/{id}', static fn ($id) => response()->json([
'detail' => "Remote book #$id",
]));
Route::get('author/{id}', static fn ($id) => response()->json([
'detail' => "Remote author #$id",
]));
});
it('will return `RemoteObject` proxy', function (): void {
$proxy = RemoteObjectFactory::setAdapter(new RemoteBookObjectAdapterTestClass($remoteObjectTestClass = new RemoteBookObjectTestClass()))
->createProxy(AbstractLocalBookObjectTestClass::class);
expect($proxy)
->toBeInstanceOf(AbstractLocalBookObjectTestClass::class)
->toBeInstanceOf(RemoteObjectInterface::class)
->and($proxy->book($id = 2))
->toEqual($remoteObjectTestClass->book($id))
->and($proxy->author($id))
->toEqual($remoteObjectTestClass->author($id));
});