-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
178 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace App\Tests; | ||
|
||
use App\Entity\Hydrometer; | ||
use App\Repository\HydrometerRepository; | ||
use Symfony\Bundle\FrameworkBundle\KernelBrowser; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
use Symfony\Component\Uid\Ulid; | ||
|
||
class BrewingFlowFunctionalTest extends WebTestCase | ||
{ | ||
private static KernelBrowser $client; | ||
|
||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$client = static::createClient(); | ||
self::bootKernel(); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
} | ||
|
||
protected function getService($id): ?object | ||
{ | ||
return self::getContainer() | ||
->get($id); | ||
} | ||
|
||
public function testCanAddHydrometer(): Hydrometer | ||
{ | ||
$crawler = self::$client->request('POST', '/new'); | ||
|
||
$this->assertResponseIsSuccessful(); | ||
$this->assertSelectorTextContains('h1', 'New hydrometer added ✅'); | ||
$this->assertSelectorTextContains('.example-wrapper', 'Your hydrometer token is: '); | ||
|
||
$hydrometerId = Ulid::fromString($crawler->filter('.example-wrapper code')->text()); | ||
|
||
$hydrometerRepository = $this->getService(HydrometerRepository::class); | ||
$hydrometer = $hydrometerRepository->find($hydrometerId); | ||
$this->assertInstanceOf(Hydrometer::class, $hydrometer); | ||
$parameterBag = $this->getService(ParameterBagInterface::class); | ||
$dataFilename = $parameterBag->get('kernel.project_dir').'/public/data/'.$hydrometer->getId().'.json'; | ||
$this->assertFileExists($dataFilename); | ||
$this->assertStringEqualsFile($dataFilename, '[]'); | ||
|
||
return $hydrometer; | ||
} | ||
|
||
/** | ||
* @depends testCanAddHydrometer | ||
*/ | ||
public function testShowsEmptyData(Hydrometer $hydrometer) | ||
{ | ||
$crawler = self::$client->request('GET', '/show/'.$hydrometer->getId()); | ||
$this->assertSelectorTextContains('h1', 'Data for '.$hydrometer->getId()); | ||
|
||
return $hydrometer; | ||
} | ||
|
||
/** | ||
* @depends testShowsEmptyData | ||
*/ | ||
public function testCanPostData(Hydrometer $hydrometer) | ||
{ | ||
$data = [ | ||
'name' => 'Hydro-Test', | ||
'ID' => '123456', | ||
'angle' => 78.9, | ||
'temperature' => 10.11, | ||
'battery' => 5.43, | ||
'gravity' => 12.34, | ||
'token' => $hydrometer->getId(), | ||
]; | ||
self::$client->request( | ||
'POST', | ||
'/data/'.$hydrometer->getId(), | ||
content: json_encode($data) | ||
); | ||
$this->assertResponseIsSuccessful(); | ||
$parameterBag = $this->getService(ParameterBagInterface::class); | ||
$dataFilename = $parameterBag->get('kernel.project_dir').'/public/data/'.$hydrometer->getId().'.json'; | ||
$jsonFromDataFile = file_get_contents($dataFilename); | ||
$savedData = json_decode($jsonFromDataFile, true, 512, JSON_THROW_ON_ERROR); | ||
unset($savedData[0]['time']); | ||
$this->assertEquals($data, $savedData[0]); | ||
|
||
return $hydrometer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Tests\Command; | ||
|
||
use App\Command\AddDataCommand; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Uid\Ulid; | ||
|
||
/** | ||
* @covers \App\Command\AddDataCommand | ||
* | ||
* @uses \Symfony\Component\Uid\Ulid | ||
*/ | ||
class AddDataCommandTest extends TestCase | ||
{ | ||
private Ulid $ulid; | ||
private AddDataCommand $command; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->ulid = new Ulid(); | ||
$this->command = new AddDataCommand($this->ulid, '{"foo":"bar"}'); | ||
} | ||
|
||
public function testGetHydrometerId() | ||
{ | ||
$this->assertSame($this->ulid, $this->command->getHydrometerId()); | ||
} | ||
|
||
public function testGetPayload() | ||
{ | ||
$this->assertSame('{"foo":"bar"}', $this->command->getPayload()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Tests\Command; | ||
|
||
use App\Command\AddHydrometerCommand; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Uid\Ulid; | ||
|
||
/** | ||
* @covers \App\Command\AddHydrometerCommand | ||
* | ||
* @uses \Symfony\Component\Uid\Ulid | ||
*/ | ||
class AddHydrometerCommandTest extends TestCase | ||
{ | ||
public function testGetId() | ||
{ | ||
$ulid = new Ulid(); | ||
$command = new AddHydrometerCommand($ulid); | ||
$this->assertSame($ulid, $command->getId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace App\Tests\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\KernelBrowser; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
|
||
class IndexControllerTest extends WebTestCase | ||
{ | ||
private static KernelBrowser $client; | ||
|
||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$client = static::createClient(); | ||
self::bootKernel(); | ||
} | ||
|
||
public function testShowsButtonToAddNewHydrometer(): void | ||
{ | ||
self::$client->request('GET', '/'); | ||
|
||
$this->assertResponseIsSuccessful(); | ||
$this->assertSelectorTextContains('h1', 'Hello Homebrewer!'); | ||
$this->assertSelectorTextContains('button', 'Add new hydrometer'); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.