Skip to content

Commit

Permalink
Complete test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Mar 23, 2024
1 parent dfe7fd7 commit 35b247a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/src/MyApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function getServices(): array
* @see https://learn.userfrosting.com/sprinkles/recipe#bakeryrecipe
*
* @return class-string<\Symfony\Component\Console\Command\Command>[]
* @codeCoverageIgnore
*/
public function getBakeryCommands(): array
{
Expand Down
39 changes: 39 additions & 0 deletions app/tests/Bakery/HelloCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

/*
* UserFrosting (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/UserFrosting
* @copyright Copyright (c) 2013-2024 Alexander Weissman & Louis Charette
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License)
*/

namespace UserFrosting\Tests\App\Controller;

use UserFrosting\App\Bakery\HelloCommand;
use UserFrosting\App\MyApp;
use UserFrosting\Testing\BakeryTester;
use UserFrosting\Testing\TestCase;

/**
* Test for HelloCommand bakery command.
*
* N.B.: This file is sage to edit or delete.
*/
class HelloCommandTest extends TestCase
{
protected string $mainSprinkle = MyApp::class;

public function testCommand(): void
{
/** @var HelloCommand */
$command = $this->ci->get(HelloCommand::class);
$result = BakeryTester::runCommand($command);

// Assert some output
$this->assertSame(0, $result->getStatusCode());
$this->assertStringContainsString('Hello world', $result->getDisplay());
}
}
42 changes: 42 additions & 0 deletions app/tests/Controller/AppControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,46 @@ public function testPageIndex(): void
$this->assertResponseStatus(200, $response);
$this->assertNotSame('', (string) $response->getBody());
}

/**
* Test index (`/about`) page.
*/
public function testPageAbout(): void
{
// Create request with method and url and fetch response
$request = $this->createRequest('GET', '/about');
$response = $this->handleRequest($request);

// Asserts
$this->assertResponseStatus(200, $response);
$this->assertNotSame('', (string) $response->getBody());
}

/**
* Test index (`/legal`) page.
*/
public function testPageLegal(): void
{
// Create request with method and url and fetch response
$request = $this->createRequest('GET', '/legal');
$response = $this->handleRequest($request);

// Asserts
$this->assertResponseStatus(200, $response);
$this->assertNotSame('', (string) $response->getBody());
}

/**
* Test index (`/privacy`) page.
*/
public function testPagePrivacy(): void
{
// Create request with method and url and fetch response
$request = $this->createRequest('GET', '/privacy');
$response = $this->handleRequest($request);

// Asserts
$this->assertResponseStatus(200, $response);
$this->assertNotSame('', (string) $response->getBody());
}
}

0 comments on commit 35b247a

Please sign in to comment.