Skip to content

Commit

Permalink
switch to attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikey179 committed Jan 16, 2024
1 parent a33090c commit b8b3a80
Show file tree
Hide file tree
Showing 56 changed files with 2,102 additions and 3,114 deletions.
69 changes: 25 additions & 44 deletions src/test/php/ParamRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* file that was distributed with this source code.
*/
namespace stubbles\input;

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use stubbles\input\errors\ParamErrors;

Expand All @@ -19,17 +22,11 @@
};
/**
* Tests for stubbles\input\ParamRequest.
*
* @group core
*/
#[Group('core')]
class ParamRequestTest extends TestCase
{
/**
* instance to test
*
* @var ParamRequest
*/
private $paramRequest;
private ParamRequest $paramRequest;

protected function setUp(): void
{
Expand All @@ -43,85 +40,69 @@ public function method(): string
};
}

/**
* @test
*/
#[Test]
public function returnsListOfParamNames(): void
{
assertThat(
$this->paramRequest->paramNames(),
equals(['foo', 'roland'])
$this->paramRequest->paramNames(),
equals(['foo', 'roland'])
);
}

/**
* @test
*/
#[Test]
public function returnsParamErrors(): void
{
assertThat(
$this->paramRequest->paramErrors(),
isInstanceOf(ParamErrors::class)
$this->paramRequest->paramErrors(),
isInstanceOf(ParamErrors::class)
);
}

/**
* @test
*/
#[Test]
public function returnsFalseOnCheckForNonExistingParam(): void
{
assertFalse($this->paramRequest->hasParam('baz'));
}

/**
* @test
*/
#[Test]
public function returnsTrueOnCheckForExistingParam(): void
{
assertTrue($this->paramRequest->hasParam('foo'));
}

/**
* @test
*/
#[Test]
public function validateParamReturnsValueValidator(): void
{
assertThat(
$this->paramRequest->validateParam('foo'),
isInstanceOf(ValueValidator::class)
$this->paramRequest->validateParam('foo'),
isInstanceOf(ValueValidator::class)
);
}

/**
* @test
*/
#[Test]
public function validateParamReturnsValueValidatorForNonExistingParam(): void
{
assertThat(
$this->paramRequest->validateParam('baz'),
isInstanceOf(ValueValidator::class)
$this->paramRequest->validateParam('baz'),
isInstanceOf(ValueValidator::class)
);
}

/**
* @test
*/
#[Test]
public function readParamReturnsValueReader(): void
{
assertThat(
$this->paramRequest->readParam('foo'),
isInstanceOf(ValueReader::class)
$this->paramRequest->readParam('foo'),
isInstanceOf(ValueReader::class)
);
}

/**
* @test
*/
#[Test]
public function readParamReturnsValueReaderForNonExistingParam(): void
{
assertThat(
$this->paramRequest->readParam('baz'),
isInstanceOf(ValueReader::class)
$this->paramRequest->readParam('baz'),
isInstanceOf(ValueReader::class)
);
}
}
46 changes: 13 additions & 33 deletions src/test/php/ParamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,96 +7,76 @@
* file that was distributed with this source code.
*/
namespace stubbles\input;

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use stubbles\values\Value;

use function bovigo\assert\{
assertThat,
assertFalse,
assertNull,
assertTrue,
predicate\equals,
predicate\isOfSize,
predicate\isSameAs
};
/**
* Tests for stubbles\input\Params.
*
* @group core
*/
#[Group('core')]
class ParamsTest extends TestCase
{
/**
* instanct to test
*
* @var Params
*/
private $params;
private Params $params;

protected function setUp(): void
{
$this->params = new Params(['foo' => 'bar', 'baz' => 'value']);
}

/**
* @test
*/
#[Test]
public function returnsFalseIfParamDoesNotExist(): void
{
assertFalse($this->params->contain('doesNotExist'));
}

/**
* @test
*/
#[Test]
public function returnsTrueIfParamDoesExist(): void
{
assertTrue($this->params->contain('foo'));
}

/**
* @test
*/
#[Test]
public function returnsNullValueIfParamDoesNotExist(): void
{
assertThat($this->params->value('doesNotExist'), isSameAs(Value::of(null)));
}

/**
* @test
*/
#[Test]
public function returnsValueIfParamExists(): void
{
assertThat($this->params->value('foo'), equals(Value::of('bar')));
}

/**
* @test
*/
#[Test]
public function returnsListOfParamNames(): void
{
assertThat($this->params->names(), equals(['foo', 'baz']));
}

/**
* @test
*/
#[Test]
public function listOfParamErrorsIsInitiallyEmpty(): void
{
assertFalse($this->params->errors()->exist());
}

/**
* @test
*/
#[Test]
public function paramsCanBeCounted(): void
{
assertThat($this->params, isOfSize(2));
}

/**
* @test
*/
#[Test]
public function canIterateOverParams(): void
{
$i = 0;
Expand Down
Loading

0 comments on commit b8b3a80

Please sign in to comment.