at the end of the day, it was inevitable

This commit is contained in:
Mo Elzubeir
2022-12-09 08:36:26 -06:00
commit 1218570914
1768 changed files with 887087 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
<?php
namespace Tests\Helper;
use PHPUnit\Framework\TestCase;
/**
* Class CssAsserter
*
* @package Helper
*/
class CssAsserter
{
/**
* @var string
*/
private $styles;
/**
* CssAsserter constructor.
*
* @param string $styles Raw css style text.
*/
public function __construct($styles)
{
$this->styles = $styles;
}
/**
* @param string $html Raw html.
*
* @return CssAsserter
*/
public static function createFromHtml($html)
{
$matches = [];
preg_match('#<style>([^<]*)</style>#i', $html, $matches);
array_shift($matches);
return new CssAsserter(implode("\n", $matches));
}
/**
* @param string $selector Css selector.
*
* @return CssAsserter
*/
public function hasSelector($selector)
{
TestCase::assertRegExp('/'.$selector.'/i', $this->styles);
return $this;
}
/**
* @param string $selector Css selector.
*
* @return CssPropertiesAsserter
*/
public function with($selector)
{
$this->hasSelector($selector);
return new CssPropertiesAsserter(preg_replace('/%s[^\{]*?\{([^\}]*?)\}/i', '$1', $this->styles), $this);
}
}