Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ function export_uses( array $uses ) {

default:
case 'functions':
$out[ $type ][] = array(
$used = array(
'name' => $name,
'line' => $element->getLineNumber(),
'end_line' => $element->getNode()->getAttribute( 'endLine' ),
Expand All @@ -1310,9 +1310,11 @@ function export_uses( array $uses ) {
$version = (string) $arguments[1]->value->value;
}

$out[ $type ][0]['deprecation_version'] = $version;
$used['deprecation_version'] = $version;
}

$out[ $type ][] = $used;

break;
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/phpunit/tests/export/uses/deprecated.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

function old_thing() {
do_something_first();
_deprecated_function( __FUNCTION__, '6.1.0', 'new_thing' );
}
44 changes: 44 additions & 0 deletions tests/phpunit/tests/export/uses/deprecated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* A test case for exporting the version of a deprecation.
*/

namespace WP_Parser\Tests;

/**
* Test that the deprecation version is exported for the deprecating call itself.
*/
class Export_Deprecated_Function_Use extends Export_UnitTestCase {

/**
* Test that the version is exported for the _deprecated_function() call.
*/
public function test_deprecating_call_has_version() {

$this->assertFunctionUsesFunction(
'old_thing'
, array(
'name' => '_deprecated_function',
'line' => 5,
'end_line' => 5,
'deprecation_version' => '6.1.0',
)
);
}

/**
* Test that the version isn't exported for a call preceding the deprecation.
*/
public function test_preceding_call_has_no_version() {

$this->assertFunctionUsesFunction(
'old_thing'
, array(
'name' => 'do_something_first',
'line' => 4,
'end_line' => 4,
)
);
}
}