77use Mpyw \LaravelPdoEmulationControl \ConnectionServiceProvider ;
88use Orchestra \Testbench \TestCase ;
99use PDO ;
10+ use PHPUnit \Framework \ExpectationFailedException ;
1011
1112class IntegrationTest extends TestCase
1213{
@@ -36,13 +37,12 @@ protected function getEnvironmentSetUp($app): void
3637 /**
3738 * @param string $property
3839 * @return \Closure|\PDO
40+ * @noinspection PhpDocMissingThrowsInspection
3941 */
40- protected function getConnectionPropertyValue (string $ property )
42+ protected function getConnectionPropertyValue (string $ property ): \ Closure | \ PDO
4143 {
42- $ db = DB ::connection ();
43- $ rp = new \ReflectionProperty ($ db , $ property );
44- $ rp ->setAccessible (true );
45- $ value = $ rp ->getValue ($ db );
44+ /** @noinspection PhpUnhandledExceptionInspection */
45+ $ value = (new \ReflectionProperty ($ db = DB ::connection (), $ property ))->getValue ($ db );
4646
4747 assert ($ value instanceof Closure || $ value instanceof PDO );
4848
@@ -80,13 +80,39 @@ protected function getPackageProviders($app): array
8080 ];
8181 }
8282
83+ /**
84+ * @throws ExpectationFailedException
85+ *
86+ * @phpstan-assert false $condition
87+ */
88+ protected function assertPdoAttrTruthy (mixed $ condition , string $ message = '' ): void {
89+ if (version_compare (PHP_VERSION , '8.4 ' , '>= ' )) {
90+ $ this ->assertTrue ($ condition , $ message );
91+ } else {
92+ $ this ->assertSame (1 , $ condition , $ message );
93+ }
94+ }
95+
96+ /**
97+ * @throws ExpectationFailedException
98+ *
99+ * @phpstan-assert false $condition
100+ */
101+ protected function assertPdoAttrFalsy (mixed $ condition , string $ message = '' ): void {
102+ if (version_compare (PHP_VERSION , '8.4 ' , '>= ' )) {
103+ $ this ->assertFalse ($ condition , $ message );
104+ } else {
105+ $ this ->assertSame (0 , $ condition , $ message );
106+ }
107+ }
108+
83109 public function testEagerEmulated (): void
84110 {
85111 $ this ->assertPdoNotResolved ();
86112 $ this ->assertReadPdoNotResolved ();
87113
88- $ this ->assertSame ( 0 , DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
89- $ this ->assertSame ( 0 , DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
114+ $ this ->assertPdoAttrFalsy ( DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
115+ $ this ->assertPdoAttrFalsy ( DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
90116
91117 $ this ->assertPdoResolved ();
92118 $ this ->assertReadPdoResolved ();
@@ -95,8 +121,8 @@ public function testEagerEmulated(): void
95121 $ this ->assertPdoResolved ();
96122 $ this ->assertReadPdoResolved ();
97123
98- $ this ->assertSame ( 1 , DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
99- $ this ->assertSame ( 1 , DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
124+ $ this ->assertPdoAttrTruthy ( DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
125+ $ this ->assertPdoAttrTruthy ( DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
100126
101127 $ this ->assertPdoResolved ();
102128 $ this ->assertReadPdoResolved ();
@@ -107,8 +133,8 @@ public function testEagerEmulated(): void
107133 $ this ->assertPdoResolved ();
108134 $ this ->assertReadPdoResolved ();
109135
110- $ this ->assertSame ( 0 , DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
111- $ this ->assertSame ( 0 , DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
136+ $ this ->assertPdoAttrFalsy ( DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
137+ $ this ->assertPdoAttrFalsy ( DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
112138
113139 $ this ->assertPdoResolved ();
114140 $ this ->assertReadPdoResolved ();
@@ -125,8 +151,8 @@ public function testLazyEmulated(): void
125151 $ this ->assertPdoNotResolved ();
126152 $ this ->assertReadPdoNotResolved ();
127153
128- $ this ->assertSame ( 1 , DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
129- $ this ->assertSame ( 1 , DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
154+ $ this ->assertPdoAttrTruthy ( DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
155+ $ this ->assertPdoAttrTruthy ( DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
130156
131157 $ this ->assertPdoResolved ();
132158 $ this ->assertReadPdoResolved ();
@@ -136,8 +162,8 @@ public function testLazyEmulated(): void
136162 $ this ->assertPdoResolved ();
137163 $ this ->assertReadPdoResolved ();
138164
139- $ this ->assertSame ( 0 , DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
140- $ this ->assertSame ( 0 , DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
165+ $ this ->assertPdoAttrFalsy ( DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
166+ $ this ->assertPdoAttrFalsy ( DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
141167
142168 $ this ->assertPdoResolved ();
143169 $ this ->assertReadPdoResolved ();
@@ -160,8 +186,8 @@ public function testCancelEmulated(): void
160186 $ this ->assertPdoNotResolved ();
161187 $ this ->assertReadPdoNotResolved ();
162188
163- $ this ->assertSame ( 0 , DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
164- $ this ->assertSame ( 0 , DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
189+ $ this ->assertPdoAttrFalsy ( DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
190+ $ this ->assertPdoAttrFalsy ( DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
165191
166192 $ this ->assertPdoResolved ();
167193 $ this ->assertReadPdoResolved ();
@@ -176,8 +202,8 @@ public function testEagerNative(): void
176202 $ this ->assertPdoNotResolved ();
177203 $ this ->assertReadPdoNotResolved ();
178204
179- $ this ->assertSame ( 1 , DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
180- $ this ->assertSame ( 1 , DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
205+ $ this ->assertPdoAttrTruthy ( DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
206+ $ this ->assertPdoAttrTruthy ( DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
181207
182208 $ this ->assertPdoResolved ();
183209 $ this ->assertReadPdoResolved ();
@@ -186,8 +212,8 @@ public function testEagerNative(): void
186212 $ this ->assertPdoResolved ();
187213 $ this ->assertReadPdoResolved ();
188214
189- $ this ->assertSame ( 0 , DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
190- $ this ->assertSame ( 0 , DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
215+ $ this ->assertPdoAttrFalsy ( DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
216+ $ this ->assertPdoAttrFalsy ( DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
191217
192218 $ this ->assertPdoResolved ();
193219 $ this ->assertReadPdoResolved ();
@@ -198,8 +224,8 @@ public function testEagerNative(): void
198224 $ this ->assertPdoResolved ();
199225 $ this ->assertReadPdoResolved ();
200226
201- $ this ->assertSame ( 1 , DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
202- $ this ->assertSame ( 1 , DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
227+ $ this ->assertPdoAttrTruthy ( DB ::getReadPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
228+ $ this ->assertPdoAttrTruthy ( DB ::getPdo ()->getAttribute (PDO ::ATTR_EMULATE_PREPARES ));
203229
204230 $ this ->assertPdoResolved ();
205231 $ this ->assertReadPdoResolved ();
0 commit comments