-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
302 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use Stratedge\Wye\Collections\BacktraceCollectionInterface; | ||
use Stratedge\Wye\Wye; | ||
|
||
class StoreBacktracesForStatementsTest extends \Tests\TestCase | ||
{ | ||
public function testTurnedOffStoresNoBacktraces() | ||
{ | ||
$stmt = Wye::makeStatement('SELECT * FROM table_name', []); | ||
|
||
$stmt->execute(); | ||
|
||
$this->assertNull($stmt->getBacktrace()); | ||
} | ||
|
||
public function testOnForAllTestsStoresBacktrace() | ||
{ | ||
Wye::logBacktraceForAllTests(); | ||
|
||
$stmt = Wye::makeStatement('SELECT * FROM table_name', []); | ||
$stmt2 = Wye::makeStatement('SELECT * FROM table_name', []); | ||
|
||
$stmt->execute(); | ||
$stmt2->execute(); | ||
|
||
$this->assertInstanceOf(BacktraceCollectionInterface::class, $stmt->getBacktrace()); | ||
$this->assertInstanceOf(BacktraceCollectionInterface::class, $stmt2->getBacktrace()); | ||
} | ||
|
||
public function testOnForTestStoresBacktrace() | ||
{ | ||
Wye::logBacktraceForTest(); | ||
|
||
$stmt = Wye::makeStatement('SELECT * FROM table_name', []); | ||
$stmt2 = Wye::makeStatement('SELECT * FROM table_name', []); | ||
|
||
$stmt->execute(); | ||
$stmt2->execute(); | ||
|
||
$this->assertInstanceOf(BacktraceCollectionInterface::class, $stmt->getBacktrace()); | ||
$this->assertInstanceOf(BacktraceCollectionInterface::class, $stmt2->getBacktrace()); | ||
} | ||
|
||
public function testOnForAllTestsSpansResets() | ||
{ | ||
Wye::logBacktraceForAllTests(); | ||
|
||
$stmt = Wye::makeStatement('SELECT * FROM table_name', []); | ||
$stmt->execute(); | ||
$this->assertInstanceOf(BacktraceCollectionInterface::class, $stmt->getBacktrace()); | ||
|
||
Wye::reset(); | ||
|
||
$stmt2 = Wye::makeStatement('SELECT * FROM table_name', []); | ||
$stmt2->execute(); | ||
$this->assertInstanceOf(BacktraceCollectionInterface::class, $stmt2->getBacktrace()); | ||
} | ||
|
||
public function testOnForOneTestDoesNotSpanResets() | ||
{ | ||
Wye::logBacktraceForTest(); | ||
|
||
$stmt = Wye::makeStatement('SELECT * FROM table_name', []); | ||
$stmt->execute(); | ||
$this->assertInstanceOf(BacktraceCollectionInterface::class, $stmt->getBacktrace()); | ||
|
||
Wye::reset(); | ||
|
||
$stmt2 = Wye::makeStatement('SELECT * FROM table_name', []); | ||
$stmt2->execute(); | ||
$this->assertNull($stmt2->getBacktrace()); | ||
} | ||
|
||
public function testBacktraceDefaultLimitAppliedIfNeeded() | ||
{ | ||
Wye::logBacktraceForTest(); | ||
Wye::setBacktraceDefaultLimit(3); | ||
|
||
$stmt = Wye::makeStatement('SELECT * FROM table_name', []); | ||
$stmt->execute(); | ||
|
||
$this->assertCount(3, $stmt->getBacktrace()); | ||
} | ||
|
||
public function testPerTestBacktraceLimitApplied() | ||
{ | ||
Wye::logBacktraceForTest(); | ||
Wye::setBacktraceDefaultLimit(3); | ||
Wye::setBacktraceLimit(2); | ||
|
||
$stmt = Wye::makeStatement('SELECT * FROM table_name', []); | ||
$stmt->execute(); | ||
|
||
$this->assertCount(2, $stmt->getBacktrace()); | ||
} | ||
|
||
public function testBacktraceDefaultLimitSpansResets() | ||
{ | ||
Wye::logBacktraceForAllTests(); | ||
Wye::setBacktraceDefaultLimit(3); | ||
|
||
$stmt = Wye::makeStatement('SELECT * FROM table_name', []); | ||
$stmt->execute(); | ||
$this->assertCount(3, $stmt->getBacktrace()); | ||
|
||
Wye::reset(); | ||
|
||
$stmt2 = Wye::makeStatement('SELECT * FROM table_name', []); | ||
$stmt2->execute(); | ||
$this->assertCount(3, $stmt2->getBacktrace()); | ||
} | ||
|
||
public function testBacktraceLimitDoesNotSpanResets() | ||
{ | ||
Wye::logBacktraceForAllTests(); | ||
Wye::setBacktraceDefaultLimit(3); | ||
Wye::setBacktraceLimit(2); | ||
|
||
$stmt = Wye::makeStatement('SELECT * FROM table_name', []); | ||
$stmt->execute(); | ||
$this->assertCount(2, $stmt->getBacktrace()); | ||
|
||
Wye::reset(); | ||
|
||
$stmt2 = Wye::makeStatement('SELECT * FROM table_name', []); | ||
$stmt2->execute(); | ||
$this->assertCount(3, $stmt2->getBacktrace()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
tests/Unit/Collections/BacktraceCollection/GetTraceTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Collections\BacktraceCollection; | ||
|
||
use Stratedge\Wye\Collections\BacktraceCollection; | ||
use Stratedge\Wye\Collections\CollectionInterface; | ||
use Stratedge\Wye\Wye; | ||
|
||
class GetTraceTest extends \Tests\TestCase | ||
{ | ||
public function testReturnsNewCollection() | ||
{ | ||
$collection = Wye::makeBacktraceCollection(); | ||
|
||
$new = $collection->getTrace(); | ||
|
||
$this->assertNotSame($new, $collection); | ||
$this->assertInstanceOf(CollectionInterface::class, $new); | ||
} | ||
|
||
public function testFormatsItemsCorrectly() | ||
{ | ||
$all = [ | ||
'class' => 'a', | ||
'type' => 'b', | ||
'function' => 'c', | ||
'file' => 'd', | ||
'line' => '1' | ||
]; | ||
|
||
$keys = [ | ||
'class', | ||
'type', | ||
'function', | ||
'file', | ||
'line', | ||
]; | ||
|
||
$data[] = $all; | ||
|
||
foreach ($keys as $key) { | ||
$data[] = array_merge($all, [$key => null]); | ||
} | ||
|
||
$collection = Wye::makeBacktraceCollection($data); | ||
|
||
$expected = [ | ||
'#0 abc() called at [d:1]', | ||
'#1 bc() called at [d:1]', | ||
'#2 ac() called at [d:1]', | ||
'#3 ab() called at [d:1]', | ||
'#4 abc() called at [:1]', | ||
'#5 abc() called at [d:0]', | ||
]; | ||
|
||
$this->assertSame($expected, $collection->getTrace()->all()); | ||
} | ||
|
||
public function testFormatsArgsCorrectly() | ||
{ | ||
$values = [ | ||
[true], | ||
[false], | ||
[null], | ||
[[]], | ||
[[1, 2]], | ||
[['test' => 1]], | ||
[Wye::makeBacktraceCollection()], | ||
['123'], | ||
['1.2'], | ||
['-8'], | ||
['cool'], | ||
[123], | ||
[1.2], | ||
[-8], | ||
['test', 'multiple', 'values'], | ||
]; | ||
|
||
foreach ($values as $value) { | ||
$data[] = ['args' => $value]; | ||
} | ||
|
||
$expected = [ | ||
'#0 (true) called at [:0]', | ||
'#1 (false) called at [:0]', | ||
'#2 (null) called at [:0]', | ||
'#3 (array(0)) called at [:0]', | ||
'#4 (sequential-array(2)) called at [:0]', | ||
'#5 (associative-array(1)) called at [:0]', | ||
'#6 (' . BacktraceCollection::class . ') called at [:0]', | ||
'#7 ("123") called at [:0]', | ||
'#8 ("1.2") called at [:0]', | ||
'#9 ("-8") called at [:0]', | ||
'#10 ("cool") called at [:0]', | ||
'#11 (123) called at [:0]', | ||
'#12 (1.2) called at [:0]', | ||
'#13 (-8) called at [:0]', | ||
'#14 ("test", "multiple", "values") called at [:0]', | ||
]; | ||
|
||
$collection = Wye::makeBacktraceCollection($data); | ||
|
||
$this->assertSame($expected, $collection->getTrace()->all()); | ||
} | ||
} |