Skip to content

Commit

Permalink
new tests, more tests, tests-tests-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidanio committed Aug 15, 2024
1 parent 7dab6f0 commit 0d362b2
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 5 deletions.
98 changes: 98 additions & 0 deletions src/tests/checkers/nullable_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package checkers

import (
"github.com/VKCOM/noverify/src/linttest"
"testing"
)

func TestNotNullableString(t *testing.T) {
test := linttest.NewSuite(t)
test.AddFile(`<?php
function nullableString(?string $a = null) {
return 0;
}
`)

test.RunAndMatch()
}

func TestNotNullableArray(t *testing.T) {
test := linttest.NewSuite(t)
test.AddFile(`<?php
/**
* @param string[] array
*/
function nullableArray(array $a = null) {
return 0;
}
`)

test.Expect = []string{
"parameter with null default value should be explicitly nullable",
}
test.RunAndMatch()
}

func TestNullableCallable(t *testing.T) {
test := linttest.NewSuite(t)
test.AddFile(`<?php
function nullableCallable(?callable $a = null) {
return 0;
}
`)

test.RunAndMatch()
}

func TestNotNullableCallable(t *testing.T) {
test := linttest.NewSuite(t)
test.AddFile(`<?php
function NotNullableCallable(callable $a = null) {
return 0;
}
`)

test.Expect = []string{
"parameter with null default value should be explicitly nullable",
}
test.RunAndMatch()
}

func TestNotNullableClasses(t *testing.T) {
test := linttest.NewSuite(t)
test.AddFile(`<?php
class MyClass1 {
}
class MyClass2 {
public function myMethod(MyClass1 $a = null) {
return 0;
}
}
`)

test.Expect = []string{
"parameter with null default value should be explicitly nullable",
"Missing PHPDoc for",
}
test.RunAndMatch()
}

func TestNullableClasses(t *testing.T) {
test := linttest.NewSuite(t)
test.AddFile(`<?php
class MyClass1 {
}
class MyClass2 {
public function myMethod(?MyClass1 $a = null) {
return 0;
}
}
`)

test.Expect = []string{
"Missing PHPDoc for",
}
test.RunAndMatch()
}
3 changes: 3 additions & 0 deletions src/tests/golden/testdata/mustache/golden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ MAYBE missingPhpdoc: Missing PHPDoc for \Mustache_Exception_UnknownTemplateExc
WARNING regexpVet: '\w' intersects with '\d' in [\w\d\.] at testdata/mustache/src/Mustache/Loader/InlineLoader.php:115
foreach (preg_split("/^@@(?= [\w\d\.]+$)/m", $data, -1) as $chunk) {
^^^^^^^^^^^^^^^^^^^^^^^
WARNING nullableType: parameter with null default value should be explicitly nullable at testdata/mustache/src/Mustache/Parser.php:73
private function buildTree(array &$tokens, array $parent = null)
^^^^^
WARNING switchDefault: Add 'default' branch to avoid unexpected unhandled condition values at testdata/mustache/src/Mustache/Parser.php:307
switch ($name) {
^
Expand Down
9 changes: 9 additions & 0 deletions src/tests/golden/testdata/parsedown/golden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ MAYBE typeHint: Specify the type for the parameter $Block in PHPDoc, 'array' t
MAYBE trailingComma: Last element in a multi-line array should have a trailing comma at testdata/parsedown/parsedown.php:560
'handler' => array(
^
WARNING nullableType: parameter with null default value should be explicitly nullable at testdata/parsedown/parsedown.php:574
protected function blockList($Line, array $CurrentBlock = null)
^^^^^
MAYBE typeHint: Specify the type for the parameter $CurrentBlock in PHPDoc, 'array' type hint too generic at testdata/parsedown/parsedown.php:574
protected function blockList($Line, array $CurrentBlock = null)
^^^^^^^^^
Expand Down Expand Up @@ -67,6 +70,9 @@ MAYBE typeHint: Specify the type for the parameter $Block in PHPDoc, 'array' t
MAYBE regexpSimplify: May re-write '/^>[ ]?+(.*+)/' as '/^> ?+(.*+)/' at testdata/parsedown/parsedown.php:774
if ($Line['text'][0] === '>' and preg_match('/^>[ ]?+(.*+)/', $Line['text'], $matches))
^^^^^^^^^^^^^^^^
WARNING nullableType: parameter with null default value should be explicitly nullable at testdata/parsedown/parsedown.php:811
protected function blockSetextHeader($Line, array $Block = null)
^^^^^
MAYBE typeHint: Specify the type for the parameter $Block in PHPDoc, 'array' type hint too generic at testdata/parsedown/parsedown.php:811
protected function blockSetextHeader($Line, array $Block = null)
^^^^^^^^^^^^^^^^^
Expand All @@ -82,6 +88,9 @@ MAYBE regexpSimplify: May re-write '/^\[(.+?)\]:[ ]*+<?(\S+?)>?(?:[ ]+["\'(](.
MAYBE ternarySimplify: Could rewrite as `$matches[3] ?? null` at testdata/parsedown/parsedown.php:881
'title' => isset($matches[3]) ? $matches[3] : null,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
WARNING nullableType: parameter with null default value should be explicitly nullable at testdata/parsedown/parsedown.php:897
protected function blockTable($Line, array $Block = null)
^^^^^
MAYBE typeHint: Specify the type for the parameter $Block in PHPDoc, 'array' type hint too generic at testdata/parsedown/parsedown.php:897
protected function blockTable($Line, array $Block = null)
^^^^^^^^^^
Expand Down
22 changes: 22 additions & 0 deletions src/tests/golden/testdata/quickfix/nullableTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

function f(string $filed = null) {
return 1;
}

function notNullableCallable(callable $a = null) {
return 0;
}

class MyClass1 {
}

class MyClass2 {
public function myMethod(MyClass1 $a = null) {
return 0;
}
}

function nullableArray(array $a = null) {
return 0;
}
5 changes: 0 additions & 5 deletions src/tests/golden/testdata/quickfix/stringNullable.php

This file was deleted.

0 comments on commit 0d362b2

Please sign in to comment.