diff --git a/resources/views/docs/mobile/4/testing/advanced.md b/resources/views/docs/mobile/4/testing/advanced.md index 61ed3615..febb6f87 100644 --- a/resources/views/docs/mobile/4/testing/advanced.md +++ b/resources/views/docs/mobile/4/testing/advanced.md @@ -29,6 +29,24 @@ it('omits the android translucency on ios', function () { `assertElement($type, $matcher)` finds an element of a wire type, optionally narrowed by a closure receiving the wire node; `assertMissingElement()` is its inverse. +`platform` also answers [platform detection](../the-basics/system#platform-detection) inside the screen +: `System::isIos()` and friends, the `isIos()` helpers, and the `@ios`, +`@android`, `@mobile` and `@web` Blade directives all report the platform you passed. + +In a test that doesn't render a screen, such as an HTTP test for a Blade view, set the `NATIVEPHP_PLATFORM` +environment variable instead . It's what the app sets on a real device. Clear it +after each test so it doesn't leak into the next one: + +```php +afterEach(fn () => putenv('NATIVEPHP_PLATFORM')); + +it('offers Sign in with Apple on iOS', function () { + putenv('NATIVEPHP_PLATFORM=ios'); + + $this->get('/login')->assertSee('Sign in with Apple'); +}); +``` + To audit a tree for screen-reader accessibility rather than a specific element, see [Accessibility](accessibility). diff --git a/resources/views/docs/mobile/4/the-basics/device.md b/resources/views/docs/mobile/4/the-basics/device.md index 53f436cc..131f74ee 100644 --- a/resources/views/docs/mobile/4/the-basics/device.md +++ b/resources/views/docs/mobile/4/the-basics/device.md @@ -76,8 +76,8 @@ $info['model']; // e.g. 'iPhone15,3' diff --git a/resources/views/docs/mobile/4/the-basics/system.md b/resources/views/docs/mobile/4/the-basics/system.md index 550244bd..9395859b 100644 --- a/resources/views/docs/mobile/4/the-basics/system.md +++ b/resources/views/docs/mobile/4/the-basics/system.md @@ -19,9 +19,27 @@ use Native\Mobile\Facades\System; System::isIos(); // true on iOS System::isAndroid(); // true on Android System::isMobile(); // true on either platform +System::platform(); // 'ios', 'android', or null outside the app ``` -Use these to branch behavior or conditionally render UI for a specific platform. +Use these to branch behavior or conditionally render UI for a specific platform. `System::platform()` + gives you the answer as a string, which saves checking both. + +On the device , the platform comes from an environment variable the app sets +before PHP starts, so these checks are cheap enough to call as often as you like, even once per row of a long list. +Before 4.7 every check asked the native side, which was far slower. + +Under [Jump](jump), PHP runs on your computer instead of the phone, so that variable isn't set. The first check asks +the connected device, and the answer is remembered after that. + +To render a screen as one platform in a test, see [Platform variants](../testing/advanced#platform-variants). + + Each is also available as a global helper function — `isIos()`, `isAndroid()`, `isMobile()` — for terse use in Blade and components: