diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index bb4d4a5..e083089 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -35,12 +35,13 @@ jobs: - name: Build Coverage Report run: XDEBUG_MODE=coverage ./vendor/bin/phpunit -c ./ --coverage-text --coverage-html ./public/coverage ### PHPDoc - #- name: Create directory public/docs - # run: mkdir ./public/docs - #- name: Install PhpDocumentor - # run: wget https://phpdoc.org/phpDocumentor.phar && chmod +x phpDocumentor.phar - #- name: Build Documentation - # run: ./phpDocumentor.phar run -d ./src -t ./public/docs + - name: Create directory public/docs + run: mkdir ./public/docs + - name: Install PhpDocumentor + ## Support PHP 7.1 + run: wget https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.1.0/phpDocumentor.phar && chmod +x phpDocumentor.phar + - name: Build Documentation + run: ./phpDocumentor.phar run -d ./src -t ./public/docs ### Deploy - name: Deploy diff --git a/composer.json b/composer.json index cc67ec6..16fb5ea 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,7 @@ "name": "phpoffice/math", "description": "Math - Manipulate Math Formula", "keywords": ["PHP","mathml", "officemathml"], + "homepage": "https://phpoffice.github.io/Math/", "type": "library", "license": "MIT", "autoload": { diff --git a/src/Math/Element/AbstractElement.php b/src/Math/Element/AbstractElement.php index 3888de9..1eef2c3 100644 --- a/src/Math/Element/AbstractElement.php +++ b/src/Math/Element/AbstractElement.php @@ -6,26 +6,4 @@ abstract class AbstractElement { - /** - * @var Math|AbstractGroupElement|null - */ - protected $parent; - - /** - * @param Math|AbstractGroupElement|null $parent - */ - public function setParent($parent): self - { - $this->parent = $parent; - - return $this; - } - - /** - * @return Math|AbstractGroupElement|null - */ - public function getParent() - { - return $this->parent; - } } diff --git a/src/Math/Element/AbstractGroupElement.php b/src/Math/Element/AbstractGroupElement.php index 85d97f3..4bc925c 100644 --- a/src/Math/Element/AbstractGroupElement.php +++ b/src/Math/Element/AbstractGroupElement.php @@ -12,7 +12,6 @@ abstract class AbstractGroupElement extends AbstractElement public function add(AbstractElement $element): self { $this->elements[] = $element; - $element->setParent($this); return $this; } @@ -23,8 +22,6 @@ public function remove(AbstractElement $element): self return $child != $element; }); - $element->setParent(null); - return $this; } diff --git a/src/Math/Element/Fraction.php b/src/Math/Element/Fraction.php index 511ac99..8812998 100644 --- a/src/Math/Element/Fraction.php +++ b/src/Math/Element/Fraction.php @@ -14,6 +14,12 @@ class Fraction extends AbstractElement */ protected $numerator; + public function __construct(AbstractElement $numerator, AbstractElement $denominator) + { + $this->setNumerator($numerator); + $this->setDenominator($denominator); + } + public function getDenominator(): AbstractElement { return $this->denominator; diff --git a/src/Math/Element/Superscript.php b/src/Math/Element/Superscript.php index 11f1a93..e3a68cc 100644 --- a/src/Math/Element/Superscript.php +++ b/src/Math/Element/Superscript.php @@ -14,6 +14,12 @@ class Superscript extends AbstractElement */ protected $superscript; + public function __construct(AbstractElement $base, AbstractElement $superscript) + { + $this->setBase($base); + $this->setSuperscript($superscript); + } + public function getBase(): AbstractElement { return $this->base; diff --git a/src/Math/Math.php b/src/Math/Math.php index 0eaeb2b..13a0e4c 100644 --- a/src/Math/Math.php +++ b/src/Math/Math.php @@ -2,48 +2,8 @@ namespace PhpOffice\Math; -use PhpOffice\Math\Element\AbstractElement; +use PhpOffice\Math\Element\AbstractGroupElement; -class Math +class Math extends AbstractGroupElement { - /** - * @var AbstractElement[] - */ - protected $elements = []; - - /** - * @param Element\AbstractElement $element - * - * @return self - */ - public function add(Element\AbstractElement $element): self - { - $this->elements[] = $element; - $element->setParent($this); - - return $this; - } - - /** - * @param Element\AbstractElement $element - * - * @return self - */ - public function remove(Element\AbstractElement $element): self - { - $this->elements = array_filter($this->elements, function ($child) use ($element) { - return $child != $element; - }); - $element->setParent(null); - - return $this; - } - - /** - * @return AbstractElement[] - */ - public function getElements(): array - { - return $this->elements; - } } diff --git a/tests/Math/Element/AbstractGroupElementTest.php b/tests/Math/Element/AbstractGroupElementTest.php new file mode 100644 index 0000000..20c5cf5 --- /dev/null +++ b/tests/Math/Element/AbstractGroupElementTest.php @@ -0,0 +1,61 @@ +assertIsArray($row->getElements()); + $this->assertCount(0, $row->getElements()); + } + + /** + * @covers \AbstractGroupElement::add + * @covers \AbstractGroupElement::getElements + */ + public function testAdd(): void + { + $identifierA = new Element\Identifier('a'); + $row = new Element\Row(); + + $this->assertCount(0, $row->getElements()); + + $this->assertInstanceOf(Element\AbstractGroupElement::class, $row->add($identifierA)); + + $this->assertCount(1, $row->getElements()); + $this->assertEquals([$identifierA], $row->getElements()); + } + + /** + * @covers \AbstractGroupElement::add + * @covers \AbstractGroupElement::getElements + */ + public function testRemove(): void + { + $identifierA = new Element\Identifier('a'); + + $row = new Element\Row(); + $row->add($identifierA); + + $this->assertCount(1, $row->getElements()); + + $this->assertInstanceOf(Element\AbstractGroupElement::class, $row->remove($identifierA)); + + $this->assertCount(0, $row->getElements()); + } +} \ No newline at end of file diff --git a/tests/Math/Element/FractionTest.php b/tests/Math/Element/FractionTest.php new file mode 100644 index 0000000..82ab2e8 --- /dev/null +++ b/tests/Math/Element/FractionTest.php @@ -0,0 +1,62 @@ +assertEquals($identifierA, $fraction->getNumerator()); + $this->assertEquals($identifierB, $fraction->getDenominator()); + } + + /** + * @covers \Fraction::getNumerator + * @covers \Fraction::setNumerator + */ + public function testBase(): void + { + $identifierA = new Element\Identifier('a'); + $identifierB = new Element\Identifier('b'); + $identifierC = new Element\Identifier('c'); + + $fraction = new Fraction($identifierA, $identifierB); + + $this->assertEquals($identifierA, $fraction->getNumerator()); + $this->assertInstanceOf(Fraction::class, $fraction->setNumerator($identifierC)); + $this->assertEquals($identifierC, $fraction->getNumerator()); + } + + /** + * @covers \Fraction::getDenominator + * @covers \Fraction::setDenominator + */ + public function testFraction(): void + { + $identifierA = new Element\Identifier('a'); + $identifierB = new Element\Identifier('b'); + $identifierC = new Element\Identifier('c'); + + $fraction = new Fraction($identifierA, $identifierB); + + $this->assertEquals($identifierB, $fraction->getDenominator()); + $this->assertInstanceOf(Fraction::class, $fraction->setDenominator($identifierC)); + $this->assertEquals($identifierC, $fraction->getDenominator()); + } +} \ No newline at end of file diff --git a/tests/Math/Element/IdentifierTest.php b/tests/Math/Element/IdentifierTest.php new file mode 100644 index 0000000..86d9568 --- /dev/null +++ b/tests/Math/Element/IdentifierTest.php @@ -0,0 +1,23 @@ +assertEquals('x', $operator->getValue()); + } +} \ No newline at end of file diff --git a/tests/Math/Element/NumericTest.php b/tests/Math/Element/NumericTest.php new file mode 100644 index 0000000..8f00ab4 --- /dev/null +++ b/tests/Math/Element/NumericTest.php @@ -0,0 +1,23 @@ +assertEquals(2, $numeric->getValue()); + } +} \ No newline at end of file diff --git a/tests/Math/Element/OperatorTest.php b/tests/Math/Element/OperatorTest.php new file mode 100644 index 0000000..b3a6779 --- /dev/null +++ b/tests/Math/Element/OperatorTest.php @@ -0,0 +1,23 @@ +assertEquals('+', $operator->getValue()); + } +} \ No newline at end of file diff --git a/tests/Math/Element/SemanticsTest.php b/tests/Math/Element/SemanticsTest.php new file mode 100644 index 0000000..b940da9 --- /dev/null +++ b/tests/Math/Element/SemanticsTest.php @@ -0,0 +1,45 @@ +assertIsArray($semantics->getAnnotations()); + $this->assertCount(0, $semantics->getAnnotations()); + } + + /** + * @covers \Superscript::addAnnotation + * @covers \Superscript::getAnnotation + * @covers \Superscript::getAnnotations + */ + public function testAnnotation(): void + { + $semantics = new Semantics(); + + $this->assertIsArray($semantics->getAnnotations()); + $this->assertCount(0, $semantics->getAnnotations()); + + $this->assertInstanceOf(Semantics::class, $semantics->addAnnotation('encoding', 'content')); + $this->assertEquals(['encoding' => 'content'], $semantics->getAnnotations()); + $this->assertCount(1, $semantics->getAnnotations()); + + $this->assertEquals('content', $semantics->getAnnotation('encoding')); + $this->assertNull($semantics->getAnnotation('notexisting')); + } +} \ No newline at end of file diff --git a/tests/Math/Element/SuperscriptTest.php b/tests/Math/Element/SuperscriptTest.php new file mode 100644 index 0000000..59660b1 --- /dev/null +++ b/tests/Math/Element/SuperscriptTest.php @@ -0,0 +1,59 @@ +assertInstanceOf(Element\Identifier::class, $superscript->getBase()); + $this->assertInstanceOf(Element\Identifier::class, $superscript->getSuperscript()); + } + + /** + * @covers \Superscript::getBase + * @covers \Superscript::setBase + */ + public function testBase(): void + { + $identifierA = new Element\Identifier('a'); + $identifierB = new Element\Identifier('b'); + $identifierC = new Element\Identifier('c'); + + $superscript = new Superscript($identifierA, $identifierB); + + $this->assertEquals($identifierA, $superscript->getBase()); + $this->assertInstanceOf(Superscript::class, $superscript->setBase($identifierC)); + $this->assertEquals($identifierC, $superscript->getBase()); + } + + /** + * @covers \Superscript::getSuperscript + * @covers \Superscript::setSuperscript + */ + public function testSuperscript(): void + { + $identifierA = new Element\Identifier('a'); + $identifierB = new Element\Identifier('b'); + $identifierC = new Element\Identifier('c'); + + $superscript = new Superscript($identifierA, $identifierB); + + $this->assertEquals($identifierB, $superscript->getSuperscript()); + $this->assertInstanceOf(Superscript::class, $superscript->setSuperscript($identifierC)); + $this->assertEquals($identifierC, $superscript->getSuperscript()); + } +} \ No newline at end of file