Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 37 additions & 36 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
name: Tests

env:
php_version: '7.3'
name: "PHPUnit"

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
inputs:
name:
description: 'PHP version'
required: true
default: '7.3'

jobs:
build:

runs-on: ubuntu-latest
phpunit:
name: "PHPUnit"
env:
LC_ALL: en_US.UTF-8
CODE_COVERAGE: n
continue-on-error: ${{ matrix.php-version == '8.1' }}

runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
php-version:
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
dependencies:
- "locked"
operating-system:
- "ubuntu-latest"
composer:
- "composer:v2"

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: "Checkout"
uses: "actions/checkout@v2"

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.3'
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, memcached
tools: composer:v2
coverage: none

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
- name: "Install PHP"
uses: shivammathur/setup-php@2.11.0
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
php-version: "${{ matrix.php-version }}"
extensions: mbstring, xml, ctype, iconv
tools: ${{matrix.composer}}

- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: "Install dependencies"
run: |
composer update --no-interaction --no-progress

# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
# Docs: https://getcomposer.org/doc/articles/scripts.md
- name: "Unit Tests"
run: composer test-unit

# - name: Run test suite
# run: composer test
- name: "Integration Tests"
run: composer test-int
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
/composer.lock
/php_errors.log
/test*.php
/coverage.clover
/.php-cs-fixer.cache
18 changes: 10 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"role": "Developer"
}
],
"archive": {
"exclude": [
"/tests", "/.github", "/phpunit.xml"
]
},
"autoload": {
"psr-4": {
"Ht7\\Html\\": "src/"
Expand All @@ -34,19 +39,16 @@
}
],
"require": {
"php": "^7.0",
"ht7/ht7-base": "master"
"php": "^7.0|^8.0",
"ht7/ht7-base": "dev-develop"
},
"require-dev": {
"phpunit/phpunit": "^7.0"
"phpunit/phpunit": "^10.5"
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"test": ".\\vendor\\bin\\phpunit --configuration .\\tests\\configuration.xml --colors --testdox",
"test-unit": "php .\\vendor\\phpunit\\phpunit\\phpunit --colors --bootstrap .\\tests\\bootstrap.php --configuration .\\tests\\configuration.xml --testsuite \"ht7 html - unit\"",
"test-func": "php .\\vendor\\phpunit\\phpunit\\phpunit --colors --bootstrap .\\tests\\bootstrap.php --configuration .\\tests\\configuration.xml --testsuite \"ht7 html - functional\"",
"test-unit1": "C:\\dev\\PHP\\current\\php.exe \"C:\\data\\edv\\php\\misc\\ht7-html\\vendor\\phpunit\\phpunit\\phpunit\" \"--colors\" \"--log-junit\" \"C:\\Users\\zoom4u\\AppData\\Local\\Temp\\nb-phpunit-log.xml\" \"--bootstrap\" \"C:\\data\\edv\\php\\misc\\ht7-html\\tests\\bootstrap.php\" \"--configuration\" \"C:\\data\\edv\\php\\misc\\ht7-html\\tests\\configuration.xml\" \"--coverage-clover\" \"C:\\Users\\zoom4u\\AppData\\Local\\Temp\\nb-phpunit-coverage.xml\" \"C:\\Program Files\\NetBeans-11.2\\netbeans\\php\\phpunit\\NetBeansSuite.php",
"phpv": "php -v"
"test-unit": "php vendor/phpunit/phpunit/phpunit --colors --testdox --configuration tests/configuration.xml --testsuite unit",
"test-int": "php vendor/phpunit/phpunit/phpunit --colors --testdox --configuration tests/configuration.xml --testsuite integration"
}
}
93 changes: 19 additions & 74 deletions src/Attribute.php
Original file line number Diff line number Diff line change
@@ -1,47 +1,18 @@
<?php

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

namespace Ht7\Html;

use \InvalidArgumentException;
use \Ht7\Base\Lists\HashListable;
use \Ht7\Html\Renderable;
use Ht7\Base\Lists\Hashable;
use Ht7\Html\Renderable;

/**
* Description of Attribute
*
* @author 1stthomas
*/
class Attribute implements HashListable, \JsonSerializable, Renderable
class Attribute implements Hashable, \JsonSerializable, Renderable
{

/**
* @var string The attribute name.
*/
protected $name;

/**
* @var string The attribute value.
*/
protected $value;

/**
* Create an instance of the attribute class.
*
* @param string $name The attribute name which must not be empty.
* @param mixed $value The attribute value.
*/
public function __construct($name, $value)
public function __construct(protected string $name, protected string|float|int|bool $value)
{
$this->setName($name);
$this->setValue($value);
}

/**
* Get a string representation of the current class.
*
Expand All @@ -54,84 +25,58 @@ public function __toString()

return $this->getName() . ($value === '' ? '' : '="' . $value . '"');
}

/**
* @Overridden
*/
public function getHash()
{
return $this->getName();
}

/**
* Get the name of the present attribute.
*
* @return string The attribute name.
*/
public function getName()
public function getName(): string
{
return $this->name;
}

/**
* Get the value of the present attribute.
*
* @return mixed The attribute value.
*/
public function getValue()
public function getValue(): string|float|int|bool
{
return $this->value;
}

/**
* {@inheritdoc}
*/
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return $this->getValue();
}

/**
* Set the name of the current attribute instance.<br />
* The name must be a string and must not be empty.
*
* @param string $name The attribute name.
* @throws InvalidArgumentException
* The name must not be empty.
*/
public function setName($name)
public function setName(string $name): static
{
if (empty($name)) {
$msg = 'The attribute name must not be empty.';
$e = sprintf($msg, gettype($name));
$e = 'The attribute name must not be empty.';

throw new InvalidArgumentException($e);
} elseif (is_string($name)) {
$this->name = $name;
} else {
$msg = 'The attribute name must be a string, found %s.';
$e = sprintf($msg, gettype($name));

throw new InvalidArgumentException($e);
throw new \InvalidArgumentException($e);
}
}

$this->name = $name;

return $this;
}
/**
* Set the value of the current attribute instance.<br />
* The value must be either string, int or float.
*
* @param mixed $value The attribute value.
* @throws InvalidArgumentException
* The value must be either string, float, int or bool.
*/
public function setValue($value)
public function setValue(string|float|int|bool $value): static
{
if (is_string($value) || is_int($value) || is_float($value)) {
$this->value = $value;
} else {
$msg = 'The attribute value must be a string, int or float, found %s.';
$e = sprintf($msg, gettype($value));
$this->value = $value;

throw new InvalidArgumentException($e);
}
return $this;
}

}
6 changes: 3 additions & 3 deletions src/Lists/AbstractRenderableList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Ht7\Html\Lists;

use \Ht7\Base\Lists\ItemList;
use \Ht7\Html\Utilities\CanRenderList;
use \Ht7\Html\Renderable;
use Ht7\Base\Lists\ItemList;
use Ht7\Html\Utilities\CanRenderList;
use Ht7\Html\Renderable;

/**
* Description of AbstractItemList
Expand Down
10 changes: 1 addition & 9 deletions src/Lists/AttributeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ class AttributeList extends HashList implements \JsonSerializable, Renderable
{

use CanRenderList;

public function __construct(array $data = [])
{
$this->divider = ' ';

parent::__construct($data);
}

/**
* {@inheritdoc}
*/
Expand All @@ -35,7 +33,6 @@ public function __toString()

return implode($this->getDivider(), $all);
}

/**
* Add an attribute to the present AttributeList.
*
Expand All @@ -56,7 +53,6 @@ public function add($item)
throw new InvalidArgumentException($e);
}
}

/**
* Add an attribute name and its value to the present AttributeList.
*
Expand All @@ -68,7 +64,6 @@ public function addPlain($name, $value)
{
return $this->add((new Attribute($name, $value)));
}

/**
* Check wheter a value can be found or not in the present AttributeList instance.
*
Expand All @@ -91,15 +86,13 @@ public function hasByValue($compare)

return false;
}

/**
* {@inheritdoc}
*/
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return $this->getAll();
}

/**
* Load the present AttributeList instance with the submitted data.
*
Expand All @@ -120,5 +113,4 @@ public function load(array $data)
}
}
}

}
5 changes: 1 addition & 4 deletions src/Lists/NodeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/
class NodeList extends AbstractRenderableList implements \JsonSerializable
{

/**
* {@inheritdoc}
*/
Expand All @@ -21,7 +20,6 @@ public function add($item)

return $this;
}

/**
* Serialize the object to a value that can beserialized natively by <code>json_encode</code>.
*
Expand All @@ -32,7 +30,7 @@ public function add($item)
*
* @return array An array representation of this instance.
*/
public function jsonSerialize()
public function jsonSerialize(): mixed
{
// $items = [];
// $all = $this->getAll();
Expand All @@ -44,5 +42,4 @@ public function jsonSerialize()
// return $items;
return $this->getAll();
}

}
Loading