Skip to content

Commit

Permalink
Fix API tests memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
fracz committed Mar 18, 2024
1 parent 29a2f3d commit 3c1817f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/SuplaBundle/Supla/SuplaServerMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function tryToHandleCommand($cmd) {
}
}
if (preg_match('#^IS-(IODEV|CLIENT|CHANNEL)-CONNECTED:(\d+),(\d+),?(\d+)?$#', $cmd, $match)) {
if ($match[1] !== 'CLIENT' || $this->faker->boolean) {
if ($match[1] !== 'CLIENT' || $this->faker->boolean()) {
return "CONNECTED:$match[3]\n";
} else {
return "DISCONNECTED:$match[3]\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ protected function addLogItems($offset = 0) {
}

$fixture = new LogItemsFixture($this->getDoctrine());
$fixture->createElectricityMeterVoltageAberrationLogItems($offset + 4, '-2 day', 1);
$fixture->createElectricityMeterVoltageAberrationLogItems($offset + 4, '-2 day', 2);
$fixture->createElectricityMeterVoltageLogItems($offset + 4, '-2 day');
$fixture->createElectricityMeterCurrentLogItems($offset + 4, '-2 day');
$fixture->createElectricityMeterPowerActiveLogItems($offset + 4, '-2 day');
$fixture->createElectricityMeterVoltageAberrationLogItems($offset + 4, '-1 days', 1);
$fixture->createElectricityMeterVoltageAberrationLogItems($offset + 4, '-1 days', 2);
$fixture->createElectricityMeterVoltageLogItems($offset + 4, '-3 hours');
$fixture->createElectricityMeterCurrentLogItems($offset + 4, '-3 hours');
$fixture->createElectricityMeterPowerActiveLogItems($offset + 4, '-3 hours');
$this->getMeasurementLogsEntityManager()->flush();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,4 +639,9 @@ public function testExecutingDirectLinkToHvac() {
$this->assertStatusCode(202, $response);
$this->assertSuplaCommandExecuted('ACTION-HVAC-SET-TEMPERATURES:1,1,8,2150,0,1');
}

protected static function createClient(array $options = [], array $server = []) {
self::ensureKernelShutdown();
return parent::createClient($options, $server);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function testDoesNotHaveWebhookAtTheBeginning() {

public function testCreatingStateWebhook() {
/** @var TestClient $client */
self::ensureKernelShutdown();
$client = self::createClient(['debug' => false], ['HTTP_AUTHORIZATION' => 'Bearer ABC', 'HTTPS' => true]);
$client->followRedirects();
$hookData = [
Expand All @@ -80,6 +81,7 @@ public function testCreatingStateWebhook() {

/** @depends testCreatingStateWebhook */
public function testGettingStateWebhook() {
self::ensureKernelShutdown();
$client = self::createClient(['debug' => false], ['HTTP_AUTHORIZATION' => 'Bearer ABC', 'HTTPS' => true]);
$client->followRedirects();
$client->apiRequestV23('GET', '/api/integrations/state-webhook');
Expand All @@ -97,6 +99,7 @@ public function testGettingStateWebhook() {

/** @depends testCreatingStateWebhook */
public function testUpdatingStateWebhook() {
self::ensureKernelShutdown();
/** @var TestClient $client */
$client = self::createClient(['debug' => false], ['HTTP_AUTHORIZATION' => 'Bearer ABC', 'HTTPS' => true]);
$client->followRedirects();
Expand All @@ -122,6 +125,7 @@ public function testUpdatingStateWebhook() {

/** @depends testUpdatingStateWebhook */
public function testDeletingStateWebhook() {
self::ensureKernelShutdown();
/** @var TestClient $client */
$client = self::createClient(['debug' => false], ['HTTP_AUTHORIZATION' => 'Bearer ABC', 'HTTPS' => true]);
$client->followRedirects();
Expand All @@ -135,7 +139,7 @@ public function testDeletingStateWebhook() {
public function testCantCreateStateWebhookForNonPublicClient() {
$client = $this->createApiClient();
$this->createAccessToken($client, $this->user, 'state_webhook', 'BCD');

self::ensureKernelShutdown();
/** @var TestClient $client */
$client = self::createClient(['debug' => false], ['HTTP_AUTHORIZATION' => 'Bearer BCD', 'HTTPS' => true]);
$client->followRedirects();
Expand All @@ -152,6 +156,7 @@ public function testCantCreateStateWebhookForNonPublicClient() {

/** @dataProvider invalidStateWebhookRequests */
public function testInvalidStateWebhookRequests($hookData) {
self::ensureKernelShutdown();
$client = self::createClient(['debug' => false], ['HTTP_AUTHORIZATION' => 'Bearer ABC', 'HTTPS' => true]);
$client->followRedirects();
$client->apiRequestV23('PUT', '/api/integrations/state-webhook', $hookData);
Expand Down

0 comments on commit 3c1817f

Please sign in to comment.