Skip to content

Commit

Permalink
Bem Helper
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Feb 7, 2020
1 parent c1e3d49 commit 58f5992
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Bem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
namespace PackagedUi\BemComponent;

class Bem
{
use BemComponentTrait;

protected $_block;

/**
* ClassBuilder constructor.
*
* @param $block
*/
public function __construct($block) { $this->_block = $block; }

public static function block($name)
{
return new static($name);
}

public function getBlockName(): string
{
return $this->_block;
}

public function modifier(string $modifier, string ...$elements): string
{
return $this->getModifier($modifier, ...$elements);
}

public function element(string ...$elements): string
{
return $this->getElementName(...$elements);
}
}
28 changes: 28 additions & 0 deletions tests/BemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
namespace PackagedUi\Tests\BemComponent;

use PackagedUi\BemComponent\Bem;
use PHPUnit\Framework\TestCase;

class BemTest extends TestCase
{
public function testBlock()
{
self::assertInstanceOf(Bem::class, Bem::block('btn'));
}

public function testElement()
{
self::assertEquals('btn__icn', Bem::block('btn')->element('icn'));
}

public function testModifier()
{
self::assertEquals('btn--disabled', Bem::block('btn')->modifier('disabled'));
}

public function testGetBlockName()
{
self::assertEquals('btn', Bem::block('btn')->getBlockName());
}
}

0 comments on commit 58f5992

Please sign in to comment.