Skip to content

Commit

Permalink
new tests for typeHints
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidanio committed Sep 5, 2024
1 parent 382f79c commit ac2b32a
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/tests/checkers/typehint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,66 @@ function f2() {
}
linttest.RunFilterMatch(test, "typeHint")
}

func TestTypeHintToFunParam(t *testing.T) {
test := linttest.NewSuite(t)
test.AddFile(`<?php
declare(strict_types = 1);
/* @param $str string */
function test($str){}
`)
test.Expect = []string{
`Non-canonical order of variable and type`,
`Type for $str can be wrote explicitly from typeHint`,
}
test.RunAndMatch()
}

func TestTypeHintClassAndFunc(t *testing.T) {
test := linttest.NewSuite(t)
test.AddFile(`<?php
declare(strict_types = 1);
class SimpleClass
{
/**
* This is what the variable does. The var line contains the type stored in this variable.
* @var string
*/
private string $foo;
/**
* This is what the variable does. The var line contains the type stored in this variable.
* @var string
*/
private $foo2 ;
/**
* @param $str string
* @param $str2 string
*/
function test($str, string $str){
}
}
/**
* @param $str string
*/
function test2($str){
}
`)
test.Expect = []string{
`Specify the access modifier for \SimpleClass::test method explicitly`,
`Non-canonical order of variable and type `,
`@param for non-existing argument $str2`,
`Non-canonical order of variable and type`,
`Type for $foo2 can be wrote explicitly from typeHint`,
`Type for $str can be wrote explicitly from typeHint`,
`Type for $str2 can be wrote explicitly from typeHint`,
`Non-canonical order of variable and type`,
`Type for $str can be wrote explicitly from typeHint`,
}
test.RunAndMatch()
}
32 changes: 32 additions & 0 deletions src/tests/golden/testdata/quickfix/phpTypeHintApply.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
declare(strict_types = 1);

class SimpleClass
{

/**
* This is what the variable does. The var line contains the type stored in this variable.
* @var string
*/
private string $foo;


/**
* This is what the variable does. The var line contains the type stored in this variable.
* @var string
*/
private string $foo2 ;

/**
* @param $str string
* @param $str2 string
*/
function test($str, $str2){
}
}

/**
* @param $str string
*/
function test2($str){
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
declare(strict_types = 1);

class SimpleClass
{

/**
* This is what the variable does. The var line contains the type stored in this variable.
* @var string
*/
private string $foo;


/**
* This is what the variable does. The var line contains the type stored in this variable.
* @var string
*/
private string $foo2 ;

/**
* @param $str string
* @param $str2 string
*/
function test(string $str, string $str){
}
}

/**
* @param $str string
*/
function test2(string $str){
}

0 comments on commit ac2b32a

Please sign in to comment.