From ca32bfb67feb11dae5a9c8b9cb2df891c196acbc Mon Sep 17 00:00:00 2001 From: recca0120 Date: Wed, 21 Dec 2022 22:42:23 +0800 Subject: [PATCH] spy closure --- .../DatabaseSqliteSchemaStateTest.php | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/tests/Database/DatabaseSqliteSchemaStateTest.php b/tests/Database/DatabaseSqliteSchemaStateTest.php index 928712674b5f..6038d0c012b3 100644 --- a/tests/Database/DatabaseSqliteSchemaStateTest.php +++ b/tests/Database/DatabaseSqliteSchemaStateTest.php @@ -26,12 +26,14 @@ public function testLoadSchemaToDatabase(): void $connection->shouldReceive('getDatabaseName')->andReturn($config['database']); $process = m::spy(Process::class); - $processFactory = m::mock(new ProcessFactory($process)); + $processFactory = m::spy(function () use ($process) { + return $process; + }); $schemaState = new SqliteSchemaState($connection, null, $processFactory); $schemaState->load('database/schema/sqlite-schema.dump'); - $processFactory->shouldHaveReceived('__invoke') + $processFactory->shouldHaveBeenCalled() ->with('sqlite3 "${:LARAVEL_LOAD_DATABASE}" < "${:LARAVEL_LOAD_PATH}"'); $process->shouldHaveReceived('mustRun')->with(null, [ @@ -57,18 +59,3 @@ public function testLoadSchemaToInMemory(): void $pdo->shouldHaveReceived('exec')->with('CREATE TABLE IF NOT EXISTS "migrations" ("id" integer not null primary key autoincrement, "migration" varchar not null, "batch" integer not null);'); } } - -class ProcessFactory -{ - private $process; - - public function __construct($process) - { - $this->process = $process; - } - - public function __invoke() - { - return $this->process; - } -}