Roni
166
10
Testing

Test if a view partial is loaded in a phpunit test

Posted 7 months ago by Roni

Is there a way to access a segment of a View response object? I'm trying to test if a view partial has been loaded in a less brittle way than just using see.

when I dd the response object I can find the view list

 #finder: Illuminate\View\FileViewFinder {#120
          #files: Illuminate\Filesystem\Filesystem {#121}
          #paths: array:1 [
            0 => "/Users/roni/code/php/laravel/5.7/munroe/resources/views"
          ]
          #views: array:13 [
            "static.new-front" => "/Users/roni/code/php/laravel/5.7/munroe/resources/views/static/new-front.blade.php"
            "segments.front.v2.events.upcomming-conferences" => "/Users/roni/code/php/laravel/5.7/munroe/resources/views/segments/front/v2/events/upcomming-conferences.blade.php"
            "segments.front.v2.weight-management" => "/Users/roni/code/php/laravel/5.7/munroe/resources/views/segments/front/v2/weight-management.blade.php"
            "segments.front.v2.notifications.sale-free-registration" => "/Users/roni/code/php/laravel/5.7/munroe/resources/views/segments/front/v2/notifications/sale-free-registration.php"
            "segments.front.v2.compression-therapy" => "/Users/roni/code/php/laravel/5.7/munroe/resources/views/segments/front/v2/compression-therapy.blade.php"
            "layouts.new-front-with-nav" => "/Users/roni/code/php/laravel/5.7/munroe/resources/views/layouts/new-front-with-nav.blade.php"
            "segments.front.v2.navbar" => "/Users/roni/code/php/laravel/5.7/munroe/resources/views/segments/front/v2/navbar.blade.php"
            "segments.front.v2.reviews.div" => "/Users/roni/code/php/laravel/5.7/munroe/resources/views/segments/front/v2/reviews/div.blade.php"
            "segments.front.v2.newsletter" => "/Users/roni/code/php/laravel/5.7/munroe/resources/views/segments/front/v2/newsletter.blade.php"
            "segments.front.map" => "/Users/roni/code/php/laravel/5.7/munroe/resources/views/segments/front/map.blade.php"
            "segments.front.v2.footer" => "/Users/roni/code/php/laravel/5.7/munroe/resources/views/segments/front/v2/footer.blade.php"
            "segments.scripts.front.v2.navbar" => "/Users/roni/code/php/laravel/5.7/munroe/resources/views/segments/scripts/front/v2/navbar.blade.php"
            "segments.scripts.front.v2.newsletter" => "/Users/roni/code/php/laravel/5.7/munroe/resources/views/segments/scripts/front/v2/newsletter.blade.php"
          ]
          #hints: array:2 [
            "notifications" => array:1 [
              0 => "/Users/roni/code/php/laravel/5.7/munroe/vendor/laravel/framework/src/Illuminate/Notifications/resources/views"
            ]
            "pagination" => array:1 [
              0 => "/Users/roni/code/php/laravel/5.7/munroe/vendor/laravel/framework/src/Illuminate/Pagination/resources/views"
            ]
          ]

but I can't figure out how to isolate that portion of the view object and test against it. Any advice is welcome.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.