cms icon indicating copy to clipboard operation
cms copied to clipboard

Addon `directory()` is null when testing an addon's views

Open edalzell opened this issue 2 years ago • 1 comments

Bug description

I have an addon that I'm writing tests for, and the functionality requires a custom view, which I have in the addons resources/views folder. This view works perfectly when addon is loaded normally, but when I'm testing, the addon's view namespace is not registered.

Specifically, the $this->getAddon()->directory() in AddonServiceProvider's bootViews is null.

You can't set directory in the TestCase manifest because directory is NOT in the inclusion list in AddonRepository when it "creates" the addon.

For some reason the provider is null here: CleanShot 2023-04-18 at 15 50 05@2x

How to reproduce

  1. Create an addon with views.
  2. try to access those views in a test

Logs

No response

Environment

Environment
Application Name: Statamic
Laravel Version: 9.52.5
PHP Version: 8.2.4
Composer Version: 2.5.5
Environment: local
Debug Mode: ENABLED
URL: transform.test
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: daily
Mail: smtp
Queue: redis
Session: file

Statamic
Addons: 11
Antlers: runtime
Stache Watcher: Enabled
Static Caching: Disabled
Version: 3.4.7 PRO

Statamic Addons
aryehraber/statamic-captcha: 1.9.1
edalzell/forma: 1.3.0
jonassiewertsen/statamic-jobs: 1.3.0
jonassiewertsen/statamic-livewire: 2.11.0
statamic/seo-pro: 4.0.1
transformstudios/events: 4.2.0
transformstudios/front: dev-feature/support-generic-notifications
transformstudios/github: dev-main
transformstudios/review: 3.8.1
transformstudios/simple: 3.6.0
transformstudios/uptime: dev-feature/other-events

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

None

Additional details

No response

edalzell avatar Apr 18 '23 22:04 edalzell

What does your addon's TestCase look like?

duncanmcclean avatar Jan 08 '24 18:01 duncanmcclean

This issue has not had recent activity and has been marked as stale — by me, a robot. Simply reply to keep it open and send me away. If you do nothing, I will close it in a week. I have no feelings, so whatever you do is fine by me.

github-actions[bot] avatar Mar 09 '24 01:03 github-actions[bot]

It looks like this issue has been fixed in v5, thanks to #9593.

duncanmcclean avatar Mar 11 '24 10:03 duncanmcclean