Source of file HeydayXhprofTest.php
Size: 4,083 Bytes - Last Modified: 2021-12-24T06:51:28+00:00
/var/www/docs.ssmods.com/process/src/code/tests/HeydayXhprofTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 | <?php class HeydayXhprofTest extends SapphireTest { public function testAppName() { HeydayXhprof::setAppName('Something'); $this->assertEquals('Something', HeydayXhprof::getAppName()); } public function testStartEnd() { HeydayXhprof::start('Start'); $this->assertEquals('Start', HeydayXhprof::getAppName()); $this->assertTrue(HeydayXhprof::isStarted()); HeydayXhprof::end(); $this->assertFalse(HeydayXhprof::isStarted()); $app = DataObject::get_one('HeydayXhprofApp', "Name = 'Start'"); $this->assertTrue($app instanceof HeydayXhprofApp); $this->assertEquals($app->safeName(), 'start'); $runs = $app->Runs(); $this->assertTrue($runs instanceof DataObjectSet); $this->assertTrue($runs->First() instanceof HeydayXhprofRun); HeydayXhprof::start('New Start Something'); HeydayXhprof::end(); $app = DataObject::get_one('HeydayXhprofApp', "Name = 'New Start Something'"); $this->assertTrue($app instanceof HeydayXhprofApp); $this->assertEquals($app->safeName(), 'new-start-something'); $apps = DataObject::get('HeydayXhprofApp'); $this->assertEquals(count($apps), 2); } public function testProbability() { HeydayXhprof::setProbability(1 / 10); $this->assertEquals(1 / 10, HeydayXhprof::getProbability()); HeydayXhprof::setProbability(10); $this->assertEquals(1, HeydayXhprof::getProbability()); HeydayXhprof::setProbability(-10); $this->assertEquals(0, HeydayXhprof::getProbability()); HeydayXhprof::setProbability(1); $this->assertTrue(HeydayXhprof::testProbability()); HeydayXhprof::setProbability(0); $this->assertFalse(HeydayXhprof::testProbability()); function run() { $sum = 0; $tot = 100000; for ($i = 0; $i < $tot; $i++) { if (HeydayXhprof::testProbability()) { $sum++; } } return round($sum / $tot, 1); } HeydayXhprof::setProbability(1 / 10); $this->assertEquals(run(), round(HeydayXhprof::getProbability(), 1)); HeydayXhprof::setProbability(1 / 100); $this->assertEquals(run(), round(HeydayXhprof::getProbability(), 1)); HeydayXhprof::setProbability(1 / 1000); $this->assertEquals(run(), round(HeydayXhprof::getProbability(), 1)); HeydayXhprof::setProbability(1 / 2); $this->assertEquals(run(), round(HeydayXhprof::getProbability(), 1)); HeydayXhprof::setProbability(1 / 3); $this->assertEquals(run(), round(HeydayXhprof::getProbability(), 1)); HeydayXhprof::setProbability(2 / 3); $this->assertEquals(run(), round(HeydayXhprof::getProbability(), 1)); } public function testExclusions() { $exclusions = array( 'hello' ); HeydayXhprof::setExclusions($exclusions); $this->assertEquals($exclusions, HeydayXhprof::getExclusions()); $exclusions = array( 'hello', 'something' ); HeydayXhprof::addExclusion('something'); $this->assertEquals($exclusions, HeydayXhprof::getExclusions()); $exclusions = array( 'hello', 'something', 'bob' ); $newExclusions = array( 'bob' ); HeydayXhprof::addExclusions($newExclusions); $this->assertEquals($exclusions, HeydayXhprof::getExclusions()); $this->assertTrue(HeydayXhprof::isExcluded('bob')); $this->assertTrue(HeydayXhprof::isExcluded('hello')); $this->assertTrue(HeydayXhprof::isExcluded('Hello')); $this->assertFalse(HeydayXhprof::isExcluded('barbie')); HeydayXhprof::setProbability(1); $this->assertTrue(HeydayXhprof::isAllowed('barbie')); $this->assertFalse(HeydayXhprof::isAllowed('/bob/')); } } |