@@ -735,6 +735,48 @@ public function testPackageCanNotBeConnectedWithThemselves(): void
735735 static ::assertFalse ($ package1 ->connect ($ package1 ));
736736 }
737737
738+ /**
739+ * Test getting services from a built package works, but getting services from
740+ * a connected built package fails.
741+ */
742+ public function testGettingServicesFromBuiltConnectedPackageFails (): void
743+ {
744+ $ package1 = $ this ->stubSimplePackage ('1 ' );
745+ $ package2 = $ this ->stubSimplePackage ('2 ' );
746+ $ package3 = $ this ->stubSimplePackage ('3 ' );
747+
748+ $ connected2 = $ package1 ->connect ($ package2 );
749+ $ connected3 = $ package1 ->connect ($ package3 );
750+
751+ // Note only P2 is "booted", while P1 and P3 are "built".
752+ $ package1 ->build ();
753+ $ package2 ->boot ();
754+ $ package3 ->build ();
755+
756+ // Test connection was successful
757+ static ::assertTrue ($ connected2 );
758+ static ::assertTrue ($ connected3 );
759+ static ::assertTrue ($ package1 ->isPackageConnected ($ package2 ->name ()));
760+ static ::assertTrue ($ package1 ->isPackageConnected ($ package3 ->name ()));
761+
762+ // We can get containers of all three packages
763+ $ container1 = $ package1 ->container ();
764+ $ container2 = $ package2 ->container ();
765+ $ container3 = $ package3 ->container ();
766+
767+ // And we can get services from all three containers if called directly
768+ static ::assertSame ('service_1 ' , $ container1 ->get ('service_1 ' )['id ' ]);
769+ static ::assertSame ('service_2 ' , $ container2 ->get ('service_2 ' )['id ' ]);
770+ static ::assertSame ('service_3 ' , $ container3 ->get ('service_3 ' )['id ' ]);
771+
772+ // And we can use Package 1 to get a service from the connected+booted Package 2
773+ $ package1 ->container ()->get ('service_2 ' );
774+ // However, we get an exception when getting a service from the connected+built Package 3
775+ /** TODO: Do we consider this a bug? See https://github.com/inpsyde/modularity/pull/49 */
776+ $ this ->expectExceptionMessageMatches ('/service_3.+not found/i ' );
777+ $ package1 ->container ()->get ('service_3 ' );
778+ }
779+
738780 /**
739781 * @test
740782 *
0 commit comments