You'll probably want to have some sort of validation logic to test if the data passed to the PDF is correct. If it isn't correct, you'll want to throw an exception.
In your test, you will then test both paths.
The happy path-- pass in a correct model instance, and assert that no exception was found.
The not so happy path-- pass in an incorrect model / data, and assert that an exception was thrown.
As far as the PDF creation goes, you can mock its creation using Laravel's built in Mockery implementation.
It is better to break the test up into at least 2 parts.
Testing your data is valid
Testing that PDF generates data that it was given
#1 is very contextual, I suppose you know how to test for that.
#2 involves passing known data to the PDF generator and using a PDF parser (e.g. https://github.com/smalot/pdfparser ) to check that the generator produced the correct data
Let me try and rephrase it, the way you are writing your current test is too "big".
Your PDF test should be something like below:
Pass "ABC" to PDF generator
Generate PDF
Check (assertSeeText) that the PDF contains "ABC"
If this test passes, means you have no issues about generating PDFs.
Then it really does not matter whether you are choosing to write "DEF" or "XYZ" to your PDF, it is safe to assume it will write correctly.
However, if your question is about how to perform step 3, i.e. assertSeeText that PDF contains "ABC"
Could you please explain which PDF facade you are using?
As I tried to explain twice earlier, no, you don't need to test if you can see $model->name and created_at.
Think of it like this, if you are trying to test if a computer can add, do you ask it to add every possible known number? You give it 2 numbers, if it returns the correct result, we assume it can perform addition correctly.
So the 2 tests to perform is,
Can the code generate a PDF containing with the example data provided?
Does the code have the correct ->name and ->created_at
What you are trying to do now is to ask the 2 questions together and it is too complicated.
Does the generated PDF have the correct ->name and ->created_at