Skip to content

Commit

Permalink
Add test for acccess services from a built connected package
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzap committed May 24, 2024
1 parent 4bf1d00 commit f6af9bf
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion tests/unit/PackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ public function testStatusForMultipleModulesWhenNotDebug(): void
*
* @test
*/
public function testPackageConnection(): void
public function testPackageConnectionWithBoot(): void
{
$module1 = $this->mockModule('module_1', ServiceModule::class);
$module1->expects('services')->andReturn($this->stubServices('service_1'));
Expand All @@ -497,6 +497,38 @@ public function testPackageConnection(): void
static::assertInstanceOf(\ArrayObject::class, $package2->container()->get('service_1'));
}

/**
* Test we can connect services across packages.
*
* @test
*/
public function testPackageConnectionWithBuildViaPackageProxyContainer(): void
{
$module1 = $this->mockModule('module_1', ServiceModule::class);
$module1->expects('services')->andReturn($this->stubServices('service_1'));
$package1 = Package::new($this->mockProperties('package_1', false))
->addModule($module1);

$module2 = $this->mockModule('module_2', ServiceModule::class);
$module2->expects('services')->andReturn($this->stubServices('service_2'));
$package2 = Package::new($this->mockProperties('package_2', false))
->addModule($module2);

Monkey\Actions\expectDone($package2->hookName(Package::ACTION_PACKAGE_CONNECTED))
->once()
->with($package1->name(), Package::STATUS_IDLE, true);

// Package1 is idle, so connection will use PackageProxyContainer
$connected = $package2->connect($package1);
$package1->build();
$package2->build();

static::assertTrue($connected);
static::assertSame(['package_1' => true], $package2->connectedPackages());
// retrieve a Package 1's service from Package 2's container.
static::assertInstanceOf(\ArrayObject::class, $package2->container()->get('service_1'));
}

/**
* Test we can not connect services when the package how call connect is booted.
*
Expand Down

0 comments on commit f6af9bf

Please sign in to comment.