(t *testing.T)
| 458 | } |
| 459 | |
| 460 | func TestFunctionParserGoTypeMismatch(t *testing.T) { |
| 461 | tests := []struct { |
| 462 | name string |
| 463 | input string |
| 464 | expected int |
| 465 | hasWarning bool |
| 466 | }{ |
| 467 | { |
| 468 | name: "parameter count mismatch should be rejected", |
| 469 | input: `package main |
| 470 | |
| 471 | //export_php:function countMismatch(string $name, int $count): string |
| 472 | func countMismatch(name *C.zend_string) unsafe.Pointer { |
| 473 | return nil |
| 474 | }`, |
| 475 | expected: 0, |
| 476 | hasWarning: true, |
| 477 | }, |
| 478 | { |
| 479 | name: "parameter type mismatch should be rejected", |
| 480 | input: `package main |
| 481 | |
| 482 | //export_php:function typeMismatch(string $name, int $count): string |
| 483 | func typeMismatch(name *C.zend_string, count string) unsafe.Pointer { |
| 484 | return nil |
| 485 | }`, |
| 486 | expected: 0, |
| 487 | hasWarning: true, |
| 488 | }, |
| 489 | { |
| 490 | name: "return type mismatch should be rejected", |
| 491 | input: `package main |
| 492 | |
| 493 | //export_php:function returnMismatch(string $name): int |
| 494 | func returnMismatch(name *C.zend_string) string { |
| 495 | return "" |
| 496 | }`, |
| 497 | expected: 0, |
| 498 | hasWarning: true, |
| 499 | }, |
| 500 | { |
| 501 | name: "valid matching types should pass", |
| 502 | input: `package main |
| 503 | |
| 504 | //export_php:function validMatch(string $name, int $count): string |
| 505 | func validMatch(name *C.zend_string, count int64) unsafe.Pointer { |
| 506 | return nil |
| 507 | }`, |
| 508 | expected: 1, |
| 509 | hasWarning: false, |
| 510 | }, |
| 511 | { |
| 512 | name: "valid bool types should pass", |
| 513 | input: `package main |
| 514 | |
| 515 | //export_php:function validBool(bool $flag): bool |
| 516 | func validBool(flag bool) bool { |
| 517 | return flag |
nothing calls this directly
no test coverage detected