New to testing, so please point out anything that sounds wrong in what I'm saying, because I may well not know it.
I'd like to test that, when you come to this page, you get a view with a paginated collection of sites, and that it has the right values. My test class is below.
class SiteTest extends TestCase
{
<snip>
public function __construct()
{
$this->baseUrl = 'https://prefix.mysite.com';
}
<snip>
/**
* Test that visiting the index page shows us the first ten sites
*
* @return void
*/
public function testItShowsAPageOfTenSites()
{
$dbSites = Site::where('is_active', 1)->orderBy('site_name', 'asc')->paginate(10);
$res = $this->call('GET', '/administration/site-management');
$this->assertResponseOk();
$this->assertViewHas('sites', $dbSites);
}
}
I get an error, though, that the paths aren't the same:
Failed asserting that two objects are equal.
--- Expected
+++ Actual
@@ @@
'currentPage' => 1
- 'path' => 'http://localhost/'
+ 'path' => 'https://prefix.mysite.com/administration/site-management/'
'query' => Array ()
'fragment' => null
'pageName' => 'page'
)
Note that I overwrite the baseUrl, because otherwise I get a 404 error. (There's some weird stuff going on in the routing that I can't change and so mostly have learned to live with in other aspects.) I tried tweaking the baseUrl in the TestCase class, but it still used localhost. Path is protected, so I can't even just force it to match.
So, is there a way to exclude it from checking the path? I'd even be content with just checking the first elements of the two match.
Further, any thoughts on the approach? I've been watching Jeffrey's videos and reading and re-reading documentation and tutorials and the like, but I still feel deeply at sea in this world of test. Thanks in advance!