You are here

class SpecTest in Little helpers 7.2

Test the instantiating spec class.

Hierarchy

  • class \Drupal\little_helpers\Services\SpecTest extends \Upal\DrupalUnitTestCase

Expanded class hierarchy of SpecTest

File

tests/Services/SpecTest.php, line 10

Namespace

Drupal\little_helpers\Services
View source
class SpecTest extends DrupalUnitTestCase {

  /**
   * Test passing keyword arguments in the spec.
   */
  public function testKwargs() {
    $spec = Spec::fromInfo([
      'class' => \SplFixedArray::class,
      'constructor' => 'fromArray',
      'arguments' => [
        '%initial',
      ],
      'calls' => [
        [
          'offsetSet',
          [
            0,
            '%other',
          ],
        ],
      ],
    ]);
    $this
      ->assertEqual([
      0,
      2,
      3,
    ], $spec
      ->instantiate([
      'initial' => [
        1,
        2,
        3,
      ],
      'other' => 0,
    ])
      ->toArray());
  }

  /**
   * Test exception when keyword argument is not defined.
   */
  public function testKwargsException() {
    $spec = Spec::fromInfo([
      'class' => \SplFixedArray::class,
      'constructor' => 'fromArray',
      'arguments' => [
        '%initial',
      ],
    ]);
    $this
      ->expectException(MissingArgumentException::class);
    $spec
      ->instantiate();
  }

  /**
   * Test that Spec::fromInfo() can handle class-only string specs.
   */
  public function testFromInfoHandlesStrings() {
    $a = Spec::fromInfo(\SplFixedArray::class)
      ->instantiate();
    $this
      ->assertInstanceOf(\SplFixedArray::class, $a);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SpecTest::testFromInfoHandlesStrings public function Test that Spec::fromInfo() can handle class-only string specs.
SpecTest::testKwargs public function Test passing keyword arguments in the spec.
SpecTest::testKwargsException public function Test exception when keyword argument is not defined.