Skip to content

Commit

Permalink
test: coverage to 78.33%
Browse files Browse the repository at this point in the history
  • Loading branch information
tobybatch committed Mar 12, 2024
1 parent d74349e commit 2578e73
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

- name: Run tests
run: |
PHPUNIT_SKIP_MYSQL_TEST=1 XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-xml target/coverage
PHPUNIT_SKIP_MYSQL_TEST=1 XDEBUG_MODE=coverage vendor/bin/phpunit
- name: Check coverage
run: |
Expand Down
3 changes: 1 addition & 2 deletions app/Wrappers/SecretStreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ class SecretStreamWrapper
* @param $path string the full path provided to @see fopen() or similar
* @param $mode string only "r" is supported
* @param $options int some options encoded as bits
* @param $open mixed not used?
*
* @return bool whether opening was successful
*/
public function stream_open($path, $mode, $options, &$open) {
public function stream_open($path, $mode, $options) {
// Check that we are in write mode.
if ($mode !== "w") {
if ($options & STREAM_REPORT_ERRORS) {
Expand Down
86 changes: 86 additions & 0 deletions tests/Unit/Controllers/Service/Admin/MarketsControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace Tests\Unit\Controllers\Service\Admin;

use App\AdminUser;
use App\Market;
use App\Sponsor;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;

class MarketsControllerTest extends TestCase
{
use DatabaseMigrations;

private AdminUser $adminUser;
private Sponsor $sponsor;
private Market $market;
private string $marketsStore;
private string $marketsUpdate;

public function setUp(): void
{
parent::setUp();

$this->adminUser = factory(AdminUser::class)->create();
$this->sponsor = factory(Sponsor::class)->create();
$this->market = factory(Market::class)->create();
}

public function testStore()
{
$name = "Earth Defense Directorate";
$message = "Give your vouchers to Dr. Theopolis";

$market = Market::where("name", '=', $name)->first();
$this->assertNull($market);

$this->actingAs($this->adminUser, 'admin')
->post(
route('admin.markets.store'),
[
"sponsor" => $this->sponsor->id,
"name" => $name,
"payment_message" => $message,
]
)->assertRedirectToRoute('admin.markets.index');

$market = Market::where("name", '=', $name)->first();
$this->assertEquals($name, $market->name);
$this->assertEquals($message, $market->payment_message);
}


public function testUpdate()
{
$name = "Earth Defense Directorate";
$message = "Give your vouchers to Dr. Theopolis";

$m = new Market([
'name' => $name,
'sponsor_id' => $this->sponsor->id,
'location' => $this->sponsor->name,
'payment_message' => $message
]);
$m->save();

$market = Market::where("name", '=', $name)->first();
$this->assertNotNull($market);

$name = "EDF";
$message = "Give your vouchers to Twiki";
$this->actingAs($this->adminUser, 'admin')
->put(
route('admin.markets.update', ["id" => $market->id]),
[
"sponsor" => $this->sponsor->id,
"name" => $name,
"payment_message" => $message,
]
)->assertRedirectToRoute('admin.markets.index');

$market = Market::where("name", '=', $name)->first();
$this->assertEquals($name, $market->name);
$this->assertEquals($message, $market->payment_message);
}
}
23 changes: 23 additions & 0 deletions tests/Unit/Wrapper/StreamWrapperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Tests\Unit\Wrapper;

use App\Wrappers\SecretStreamWrapper;
use Illuminate\Foundation\Testing\TestCase;
use Tests\CreatesApplication;

class StreamWrapperTest extends TestCase
{
use CreatesApplication;

public function testInvocationErrors()
{
$ssw = new SecretStreamWrapper();

$result = $ssw->stream_open("any/path", "r", null);
$this->assertFalse($result);

$result = $ssw->stream_open("any/path", "w", null);
$this->assertFalse($result);
}
}

0 comments on commit 2578e73

Please sign in to comment.