-
In my tests I'm creating an asset and adding to my entry like this: use Statamic\Facades\AssetContainer;
use Statamic\Facades\Asset;
public function createPairsGame(String $type)
{
Storage::fake('local');
AssetContainer::make('spaces')->disk('local')->save();
$bgAsset = (new Asset)->container('spaces')->path('/assets/images/bg-2023.jpg');
Entry::make()
->collection('pairs_game')
->slug('ipad-pairs-game')
->blueprint('ipad_pairs_game')
->data([
'title' => fake()->text(),
'main_background_image' => $bgAsset->path,
])
->save();
} The At first this seems to work - inside my controller I have: ray($this->data()); Illuminate\Support\Collection {#4430▶
#items: array:2 [▶
"title" => "Qui illo totam soluta dolorem dolor consequatur sit. Id fuga dolor iste quia qui. Dolor sit sit voluptatem. Quisquam nesciunt voluptas omnis. Et esse ratione ut aliquid."
"main_background_image" => "assets/images/bg-2023.jpg"
]
#escapeWhenCastingToString: false
} However calling
This is not what I want. I want the actual Statamic\Assets\Asset returned.
Now when I run
^^^ This is correct. I want the asset to be loaded - yay! But I can't figure out why it's behaving different in my testing environment. It'll be related to how I set up the test I'm sure, but I'm stumped on this one. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
In your blueprint, which asset container is the |
Beta Was this translation helpful? Give feedback.
-
@duncanmcclean This wasn't the issue but you definitely set me on the right path... In my tests setup I have Thanks |
Beta Was this translation helpful? Give feedback.
@duncanmcclean This wasn't the issue but you definitely set me on the right path...
In my tests setup I have
$this->preventSavingStacheItemsToDisk();
which, of course, prevents the actual assetContainers being used. I'll get this reworked and re-open if I still can't get it to work.Thanks