Skip to content

Commit

Permalink
Convert unittests to PHP 8 attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Oct 4, 2020
1 parent 4d0b736 commit 71c494e
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 55 deletions.
35 changes: 18 additions & 17 deletions src/test/php/unittest/web/tests/AssertionMethodsTest.class.php
Original file line number Diff line number Diff line change
@@ -1,113 +1,114 @@
<?php namespace unittest\web\tests;

use peer\http\HttpConstants;
use peer\URL;
use peer\http\HttpConstants;
use text\regex\Pattern;
use unittest\Test;

class AssertionMethodsTest extends WebTestCaseTest {

#[@test]
#[Test]
public function assertStatus() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], '');
$this->fixture->beginAt('/');
$this->fixture->assertStatus(HttpConstants::STATUS_OK);
}

#[@test]
#[Test]
public function assertStatusIn() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], '');
$this->fixture->beginAt('/');
$this->fixture->assertStatusIn([HttpConstants::STATUS_OK]);
}

#[@test]
#[Test]
public function assertUrlEquals() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], '');
$this->fixture->beginAt('/');
$this->fixture->assertUrlEquals(new URL('http://localhost/'));
}

#[@test]
#[Test]
public function assertContentType() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, ['Content-Type: text/plain'], '');
$this->fixture->beginAt('/');
$this->fixture->assertContentType('text/plain');
}

#[@test]
#[Test]
public function assertContentType_with_charset() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, ['Content-Type: text/xml; charset=utf-8']);
$this->fixture->beginAt('/');
$this->fixture->assertContentType('text/xml; charset=utf-8');
}

#[@test]
#[Test]
public function assertHeader() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, ['ETag: "214ceb4b-980-3a7bbd9630480"'], '');
$this->fixture->beginAt('/');
$this->fixture->assertHeader('ETag', '"214ceb4b-980-3a7bbd9630480"');
}

#[@test]
#[Test]
public function assertElementPresent() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], '<html><body><div id="content"/></html>');
$this->fixture->beginAt('/');
$this->fixture->assertElementPresent('content');
}

#[@test]
#[Test]
public function assertTextPresent() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], '<html><body>Content</html>');
$this->fixture->beginAt('/');
$this->fixture->assertTextPresent('Content');
}

#[@test]
#[Test]
public function assertTextPatternPresent() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], '<html><body>Content</html>');
$this->fixture->beginAt('/');
$this->fixture->assertTextPatternPresent(new Pattern('content', Pattern::CASE_INSENSITIVE));
}

#[@test]
#[Test]
public function assertImagePresent() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], '<html><body><img src="blank.gif"/></html>');
$this->fixture->beginAt('/');
$this->fixture->assertImagePresent('blank.gif');
}

#[@test]
#[Test]
public function assertLinkPresent() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], '<html><body><a href="http://example.com/">.</a></html>');
$this->fixture->beginAt('/');
$this->fixture->assertLinkPresent('http://example.com/');
}

#[@test]
#[Test]
public function assertLinkPresentWithText() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], '<html><body><a href="http://example.com/">Example</a></html>');
$this->fixture->beginAt('/');
$this->fixture->assertLinkPresentWithText('Example');
}

#[@test]
#[Test]
public function assertFormPresent_without_name() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], '<html><body><form></form></html>');
$this->fixture->beginAt('/');
$this->fixture->assertFormPresent();
}

#[@test]
#[Test]
public function assertFormPresent_with_name() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], '<html><body><form name="login"></form></html>');
$this->fixture->beginAt('/');
$this->fixture->assertFormPresent('login');
}

#[@test]
#[Test]
public function assertTitleEquals() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], '<html><head><title>Test</title></head><body/></html>');
$this->fixture->beginAt('/');
$this->fixture->assertTitleEquals('Test');
}
}
}
7 changes: 4 additions & 3 deletions src/test/php/unittest/web/tests/CookiesTest.class.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
<?php namespace unittest\web\tests;

use peer\http\HttpConstants;
use unittest\Test;
use unittest\web\Cookie;

class CookiesTest extends WebTestCaseTest {

#[@test]
#[Test]
public function no_cookies_present() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], '');
$this->fixture->beginAt('/');
$this->assertEquals([], $this->fixture->getCookies());
}

#[@test]
#[Test]
public function single_cookie_present() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, ['Set-Cookie: uid=6100'], '');
$this->fixture->beginAt('/');
$this->assertEquals(['uid' => new Cookie('uid', '6100')], $this->fixture->getCookies());
}

#[@test]
#[Test]
public function multiple_cookies_present() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, ['Set-Cookie: uid=6100', 'Set-Cookie: session=abcd'], '');
$this->fixture->beginAt('/');
Expand Down
3 changes: 2 additions & 1 deletion src/test/php/unittest/web/tests/ElementsTest.class.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php namespace unittest\web\tests;

use peer\http\HttpConstants;
use unittest\Test;

class ElementsTest extends WebTestCaseTest {

#[@test]
#[Test]
public function elements() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], trim('
<html>
Expand Down
15 changes: 8 additions & 7 deletions src/test/php/unittest/web/tests/EncodingTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use peer\http\HttpConstants;
use text\regex\Pattern;
use unittest\{Test, Values};

class EncodingTest extends WebTestCaseTest {
private static $FIXTURE;
Expand Down Expand Up @@ -41,49 +42,49 @@ private function fixtures() {
];
}

#[@test, @values('fixtures')]
#[Test, Values('fixtures')]
public function title($headers, $fixture) {
$this->fixture->respondWith(HttpConstants::STATUS_OK, $headers, $fixture);
$this->fixture->beginAt('/');
$this->fixture->assertTitleEquals('Über-Tests');
}

#[@test, @values('fixtures')]
#[Test, Values('fixtures')]
public function link($headers, $fixture) {
$this->fixture->respondWith(HttpConstants::STATUS_OK, $headers, $fixture);
$this->fixture->beginAt('/');
$this->fixture->assertLinkPresentWithText('Über-Example');
}

#[@test, @values('fixtures')]
#[Test, Values('fixtures')]
public function input($headers, $fixture) {
$this->fixture->respondWith(HttpConstants::STATUS_OK, $headers, $fixture);
$this->fixture->beginAt('/');
$this->assertEquals('Übercoder', $this->fixture->getForm()->getField('uber')->getValue());
}

#[@test, @values('fixtures')]
#[Test, Values('fixtures')]
public function option($headers, $fixture) {
$this->fixture->respondWith(HttpConstants::STATUS_OK, $headers, $fixture);
$this->fixture->beginAt('/');
$this->assertEquals('Überwoman', $this->fixture->getForm()->getField('gender')->getOptions()[0]->getText());
}

#[@test, @values('fixtures')]
#[Test, Values('fixtures')]
public function textarea($headers, $fixture) {
$this->fixture->respondWith(HttpConstants::STATUS_OK, $headers, $fixture);
$this->fixture->beginAt('/');
$this->assertEquals('Übercoder', $this->fixture->getForm()->getField('umlauts')->getValue());
}

#[@test, @values('fixtures')]
#[Test, Values('fixtures')]
public function text($headers, $fixture) {
$this->fixture->respondWith(HttpConstants::STATUS_OK, $headers, $fixture);
$this->fixture->beginAt('/');
$this->fixture->assertTextPresent('über tests');
}

#[@test, @values('fixtures')]
#[Test, Values('fixtures')]
public function pattern($headers, $fixture) {
$this->fixture->respondWith(HttpConstants::STATUS_OK, $headers, $fixture);
$this->fixture->beginAt('/');
Expand Down
27 changes: 13 additions & 14 deletions src/test/php/unittest/web/tests/FormElementsTest.class.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php namespace unittest\web\tests;

use lang\IllegalArgumentException;
use unittest\web\InputField;
use unittest\web\SelectField;
use unittest\web\TextAreaField;
use peer\http\HttpConstants;
use unittest\web\{InputField, SelectField, TextAreaField};
use unittest\{Expect, Test};

class FormElementsTest extends WebTestCaseTest {

Expand Down Expand Up @@ -49,15 +48,15 @@ protected function formFixture() {
');
}

#[@test, @expect(IllegalArgumentException::class)]
#[Test, Expect(IllegalArgumentException::class)]
public function nonExistantField() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], $this->formFixture());
$this->fixture->beginAt('/');

$this->fixture->getForm()->getField('does-not-exist');
}

#[@test]
#[Test]
public function textFieldWithoutValue() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], $this->formFixture());
$this->fixture->beginAt('/');
Expand All @@ -69,7 +68,7 @@ public function textFieldWithoutValue() {
}
}

#[@test]
#[Test]
public function textFieldWithEmptyValue() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], $this->formFixture());
$this->fixture->beginAt('/');
Expand All @@ -81,7 +80,7 @@ public function textFieldWithEmptyValue() {
}
}

#[@test]
#[Test]
public function textFieldWithValue() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], $this->formFixture());
$this->fixture->beginAt('/');
Expand All @@ -93,7 +92,7 @@ public function textFieldWithValue() {
}
}

#[@test]
#[Test]
public function textFieldWithUmlautInValue() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], $this->formFixture());
$this->fixture->beginAt('/');
Expand All @@ -105,7 +104,7 @@ public function textFieldWithUmlautInValue() {
}
}

#[@test]
#[Test]
public function selectFieldWithoutSelected() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], $this->formFixture());
$this->fixture->beginAt('/');
Expand All @@ -117,7 +116,7 @@ public function selectFieldWithoutSelected() {
}
}

#[@test]
#[Test]
public function selectFieldWithSelected() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], $this->formFixture());
$this->fixture->beginAt('/');
Expand All @@ -129,7 +128,7 @@ public function selectFieldWithSelected() {
}
}

#[@test]
#[Test]
public function selectFieldOptions() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], $this->formFixture());
$this->fixture->beginAt('/');
Expand All @@ -155,15 +154,15 @@ public function selectFieldOptions() {
}
}

#[@test]
#[Test]
public function selectFieldNoSelectedOptions() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], $this->formFixture());
$this->fixture->beginAt('/');

$this->assertEquals([], $this->fixture->getForm()->getField('gender')->getSelectedOptions());
}

#[@test]
#[Test]
public function selectFieldSelectedOptions() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], $this->formFixture());
$this->fixture->beginAt('/');
Expand All @@ -177,7 +176,7 @@ public function selectFieldSelectedOptions() {
}
}

#[@test]
#[Test]
public function textArea() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], $this->formFixture());
$this->fixture->beginAt('/');
Expand Down
11 changes: 6 additions & 5 deletions src/test/php/unittest/web/tests/FormsTest.class.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php namespace unittest\web\tests;

use unittest\web\Form;
use peer\http\HttpConstants;
use unittest\Test;
use unittest\web\Form;

class FormsTest extends WebTestCaseTest {

Expand All @@ -19,7 +20,7 @@ private function assertForm($action, $method, $form) {
$this->assertEquals($method, $form->getMethod());
}

#[@test]
#[Test]
public function unnamedForm() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], trim('
<html>
Expand All @@ -36,7 +37,7 @@ public function unnamedForm() {
$this->fixture->assertFormPresent();
}

#[@test]
#[Test]
public function noForm() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], trim('
<html>
Expand All @@ -53,7 +54,7 @@ public function noForm() {
$this->fixture->assertFormNotPresent();
}

#[@test]
#[Test]
public function namedForms() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], trim('
<html>
Expand All @@ -73,7 +74,7 @@ public function namedForms() {
$this->fixture->assertFormNotPresent('green');
}

#[@test]
#[Test]
public function getForm() {
$this->fixture->respondWith(HttpConstants::STATUS_OK, [], trim('
<html>
Expand Down
Loading

0 comments on commit 71c494e

Please sign in to comment.