You are here

StatsDTest.php in StatsD 7.2

Tests for statsd module.

File

lib/Drupal/statsd/Tests/StatsDTest.php
View source
<?php

/**
 * @file
 * Tests for statsd module.
 */
namespace Drupal\statsd\Tests;


/**
 * Unit tests for statsd.inc
 */
class StatsDTest extends \DrupalUnitTestCase {

  /**
   * Describe the test suite.
   */
  public static function getInfo() {
    return array(
      'name' => 'StatsD Unit Test',
      'description' => 'Very simple usecase of unit testing the statsd object.',
      'group' => 'StatsD',
    );
  }

  /**
   * Enable module.
   */
  public function setUp() {
    parent::setUp('statsd');
  }

  /**
   * Make sure all valid arguments are reflected in new instance.
   */
  public function testConstructorArgumentsHappy() {
    $parameters = array(
      'enabled' => 'foo',
      'sampleRate' => 0.42,
      'host' => '10.0.0.1',
      'port' => 80,
      'prefix' => 'pre',
      'suffix' => 'suf',
    );
    $statsd = new \StatsD($parameters);
    foreach ($parameters as $name => $value) {
      $this
        ->assertTrue(property_exists($statsd, $name) && $statsd->{$name} == $value, "{$name} is assigned correctly.");
    }
  }

  /**
   * Make sure undefined arguments are not reflected in new instance.
   */
  public function testConstructorArgumentsSadExtra() {
    $parameters = array(
      'foo' => 'bar',
    );
    $statsd = new \StatsD($parameters);
    $this
      ->assertTrue(!isset($statsd->foo), 'Extra parameters are ignored.');
  }

}

Classes

Namesort descending Description
StatsDTest Unit tests for statsd.inc