DJStarCOM /
newrelic
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace DJStarCOM\NewRelic; |
||
| 4 | |||
| 5 | use DJStarCOM\NewRelic\Config\TransactionConfig; |
||
| 6 | use DJStarCOM\NewRelic\Stub\Foo; |
||
| 7 | use PHPUnit\Framework\TestCase; |
||
| 8 | |||
| 9 | class TransactionTest extends TestCase |
||
| 10 | { |
||
| 11 | private $transaction; |
||
| 12 | public static $transactionName; |
||
| 13 | public static $applicationNameStarted; |
||
| 14 | public static $customParameters; |
||
| 15 | public static $endTransaction; |
||
| 16 | public static $exceptionMessage; |
||
| 17 | public static $exception; |
||
| 18 | public static $applicationName; |
||
| 19 | public static $extensionAvailable; |
||
| 20 | public static $transactionsCount; |
||
| 21 | public static $isBackground; |
||
| 22 | |||
| 23 | private $config; |
||
| 24 | |||
| 25 | public function setUp() |
||
| 26 | { |
||
| 27 | $this->config = new TransactionConfig(); |
||
| 28 | $this->config->applicationName = 'RTG'; |
||
| 29 | $this->config->transactionName = 'Track'; |
||
| 30 | self::$extensionAvailable = true; |
||
| 31 | $this->transaction = new Transaction(new Foo(), $this->config); |
||
| 32 | self::$endTransaction = false; |
||
| 33 | self::$transactionsCount = 0; |
||
| 34 | } |
||
| 35 | |||
| 36 | public function testHasAbilityToSetApplicationName() |
||
| 37 | { |
||
| 38 | $this->transaction->bar(); |
||
|
0 ignored issues
–
show
|
|||
| 39 | |||
| 40 | $this->assertEquals('RTG', self::$applicationName); |
||
| 41 | } |
||
| 42 | |||
| 43 | public function testCanSetBackgroundJob() |
||
| 44 | { |
||
| 45 | $this->transaction->bar(); |
||
|
0 ignored issues
–
show
The method
bar does not exist on object<DJStarCOM\NewRelic\Transaction>? Since you implemented __call, maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
| 46 | |||
| 47 | $this->assertEquals(true, self::$isBackground); |
||
| 48 | } |
||
| 49 | |||
| 50 | public function testStartATransaction() |
||
| 51 | { |
||
| 52 | $this->transaction->bar(); |
||
|
0 ignored issues
–
show
The method
bar does not exist on object<DJStarCOM\NewRelic\Transaction>? Since you implemented __call, maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
| 53 | |||
| 54 | $this->assertEquals('RTG', self::$applicationNameStarted); |
||
| 55 | } |
||
| 56 | |||
| 57 | public function testCanSetTransactionName() |
||
| 58 | { |
||
| 59 | $this->transaction->bar(); |
||
|
0 ignored issues
–
show
The method
bar does not exist on object<DJStarCOM\NewRelic\Transaction>? Since you implemented __call, maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
| 60 | |||
| 61 | $this->assertEquals('Track', self::$transactionName); |
||
| 62 | } |
||
| 63 | |||
| 64 | public function testCanAddComplexArgumentsToNewRelic() |
||
| 65 | { |
||
| 66 | $complexArgument = [ |
||
| 67 | 0 => 'simple', |
||
| 68 | 1 => ['array' => 'simple'], |
||
| 69 | 2 => ['string' => 'simple', 'named array' => ['json'], 'object' => new \stdClass()] |
||
| 70 | ]; |
||
| 71 | |||
| 72 | $this->transaction->bar($complexArgument[0], $complexArgument[1], $complexArgument[2]); |
||
|
0 ignored issues
–
show
The method
bar does not exist on object<DJStarCOM\NewRelic\Transaction>? Since you implemented __call, maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
| 73 | |||
| 74 | $this->assertEquals([ |
||
| 75 | '0' => 'simple', |
||
| 76 | 'array' => 'simple', |
||
| 77 | 'string' => 'simple', |
||
| 78 | 'named array' => '["json"]', |
||
| 79 | 'object' => '{}' |
||
| 80 | ], self::$customParameters); |
||
| 81 | } |
||
| 82 | |||
| 83 | public function testArgumentAreCorrectedPassedToObject() |
||
| 84 | { |
||
| 85 | $argument = 'NRI'; |
||
| 86 | |||
| 87 | $returnedArgument = $this->transaction->bar($argument); |
||
|
0 ignored issues
–
show
The method
bar does not exist on object<DJStarCOM\NewRelic\Transaction>? Since you implemented __call, maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
| 88 | |||
| 89 | $this->assertEquals($argument, $returnedArgument); |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @expectedException \InvalidArgumentException |
||
| 94 | * @expectedExceptionMessage NRI |
||
| 95 | */ |
||
| 96 | public function testExceptionStillTheSame() |
||
| 97 | { |
||
| 98 | $expectedException = new \InvalidArgumentException('NRI'); |
||
| 99 | |||
| 100 | $this->transaction->fooThrowThisException($expectedException); |
||
|
0 ignored issues
–
show
The method
fooThrowThisException does not exist on object<DJStarCOM\NewRelic\Transaction>? Since you implemented __call, maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
| 101 | } |
||
| 102 | |||
| 103 | public function testExceptionIsRecordedOnNewRelic() |
||
| 104 | { |
||
| 105 | $expectedException = new \InvalidArgumentException('NRI'); |
||
| 106 | |||
| 107 | try { |
||
| 108 | $this->transaction->fooThrowThisException($expectedException); |
||
|
0 ignored issues
–
show
The method
fooThrowThisException does not exist on object<DJStarCOM\NewRelic\Transaction>? Since you implemented __call, maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
| 109 | } catch (\Exception $exception) { |
||
| 110 | //Ignoring exceptions |
||
| 111 | } |
||
| 112 | |||
| 113 | $this->assertNotEmpty(self::$exceptionMessage); |
||
| 114 | $this->assertEquals($expectedException, self::$exception); |
||
| 115 | } |
||
| 116 | |||
| 117 | public function testEndTransactionAndSendToNewRelicWhenAnExceptionHappen() |
||
| 118 | { |
||
| 119 | $expectedException = new \InvalidArgumentException('NRI'); |
||
| 120 | |||
| 121 | try { |
||
| 122 | $this->transaction->fooThrowThisException($expectedException); |
||
|
0 ignored issues
–
show
The method
fooThrowThisException does not exist on object<DJStarCOM\NewRelic\Transaction>? Since you implemented __call, maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
| 123 | } catch (\Exception $exception) { |
||
| 124 | //Ignoring exceptions |
||
| 125 | } |
||
| 126 | |||
| 127 | $this->assertTrue(self::$endTransaction); |
||
| 128 | } |
||
| 129 | |||
| 130 | public function testEndTransactionAndSendToNewRelic() |
||
| 131 | { |
||
| 132 | $this->transaction->bar(); |
||
|
0 ignored issues
–
show
The method
bar does not exist on object<DJStarCOM\NewRelic\Transaction>? Since you implemented __call, maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
| 133 | |||
| 134 | $this->assertTrue(self::$endTransaction); |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @expectedException \InvalidArgumentException |
||
| 139 | */ |
||
| 140 | public function testNonObject() |
||
| 141 | { |
||
| 142 | new Transaction('NRI', new TransactionConfig()); |
||
| 143 | } |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @expectedException \DJStarCOM\NewRelic\Exception\NotLoadedNewRelicExtensionException |
||
| 147 | */ |
||
| 148 | public function testExceptionIfExtensionIsNotLoaded() |
||
| 149 | { |
||
| 150 | self::$extensionAvailable = false; |
||
| 151 | |||
| 152 | new Transaction(new \StdClass, new TransactionConfig()); |
||
| 153 | } |
||
| 154 | |||
| 155 | public function testTransactioIsStartedOnlyForDesiredMethodCall() |
||
| 156 | { |
||
| 157 | $this->config->monitoredMethodName = 'foo'; |
||
| 158 | |||
| 159 | $this->transaction->bar(); |
||
|
0 ignored issues
–
show
The method
bar does not exist on object<DJStarCOM\NewRelic\Transaction>? Since you implemented __call, maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
| 160 | $this->transaction->foo(); |
||
|
0 ignored issues
–
show
The method
foo does not exist on object<DJStarCOM\NewRelic\Transaction>? Since you implemented __call, maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
| 161 | |||
| 162 | $this->assertEquals(1, self::$transactionsCount); |
||
| 163 | } |
||
| 164 | } |
||
| 165 | |||
| 166 | function newrelic_start_transaction($appName) |
||
| 167 | { |
||
| 168 | TransactionTest::$applicationNameStarted = $appName; |
||
| 169 | TransactionTest::$transactionsCount++; |
||
| 170 | } |
||
| 171 | |||
| 172 | function newrelic_name_transaction($transactionName) |
||
| 173 | { |
||
| 174 | TransactionTest::$transactionName = $transactionName; |
||
| 175 | } |
||
| 176 | |||
| 177 | function newrelic_add_custom_parameter($key, $value) |
||
| 178 | { |
||
| 179 | TransactionTest::$customParameters[$key] = $value; |
||
| 180 | return true; |
||
| 181 | } |
||
| 182 | |||
| 183 | function newrelic_end_transaction() |
||
| 184 | { |
||
| 185 | TransactionTest::$endTransaction = true; |
||
| 186 | } |
||
| 187 | |||
| 188 | function newrelic_notice_error($exceptionMessage, \Exception $exception = null) |
||
| 189 | { |
||
| 190 | TransactionTest::$exceptionMessage = $exceptionMessage; |
||
| 191 | TransactionTest::$exception = $exception; |
||
| 192 | } |
||
| 193 | |||
| 194 | function extension_loaded($extension) |
||
|
0 ignored issues
–
show
|
|||
| 195 | { |
||
| 196 | return TransactionTest::$extensionAvailable; |
||
| 197 | } |
||
| 198 | |||
| 199 | function newrelic_set_appname($appName) |
||
| 200 | { |
||
| 201 | TransactionTest::$applicationName = $appName; |
||
| 202 | } |
||
| 203 | |||
| 204 | function newrelic_background_job($isBackground) |
||
| 205 | { |
||
| 206 | TransactionTest::$isBackground = $isBackground; |
||
| 207 | } |
||
| 208 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: