MCPcopy Create free account
hub / github.com/php/frankenphp / TestConstants

Function TestConstants

internal/extgen/integration_test.go:460–559  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

458}
459
460func TestConstants(t *testing.T) {
461 suite := setupTest(t)
462
463 sourceFile := filepath.Join("..", "..", "testdata", "integration", "constants.go")
464 sourceFile, err := filepath.Abs(sourceFile)
465 require.NoError(t, err)
466 defer suite.cleanupGeneratedFiles(sourceFile)
467
468 targetFile, err := suite.createGoModule(sourceFile)
469 require.NoError(t, err)
470
471 err = suite.runExtensionInit(targetFile)
472 require.NoError(t, err)
473
474 _, err = suite.compileFrankenPHP(filepath.Dir(targetFile))
475 require.NoError(t, err)
476
477 err = suite.verifyPHPSymbols(
478 []string{"test_with_constants"},
479 []string{"Config"},
480 []string{
481 "TEST_MAX_RETRIES", "TEST_API_VERSION", "TEST_ENABLED", "TEST_PI",
482 "STATUS_PENDING", "STATUS_PROCESSING", "STATUS_COMPLETED",
483 "ONE", "TWO",
484 },
485 )
486 require.NoError(t, err, "all constants, functions, and classes should be accessible from PHP")
487
488 err = suite.verifyFunctionBehavior(`<?php
489if (TEST_MAX_RETRIES !== 100) {
490 echo "FAIL: TEST_MAX_RETRIES expected 100, got " . TEST_MAX_RETRIES;
491 exit(1);
492}
493
494if (TEST_API_VERSION !== "2.0.0") {
495 echo "FAIL: TEST_API_VERSION expected '2.0.0', got '" . TEST_API_VERSION . "'";
496 exit(1);
497}
498
499if (TEST_ENABLED !== true) {
500var_dump(TEST_ENABLED);
501 echo "FAIL: TEST_ENABLED expected true, got " . (TEST_ENABLED ? "true" : "false");
502 exit(1);
503}
504
505if (abs(TEST_PI - 3.14159) > 0.00001) {
506 echo "FAIL: TEST_PI expected 3.14159, got " . TEST_PI;
507 exit(1);
508}
509
510if (Config::MODE_DEBUG !== 1) {
511 echo "FAIL: Config::MODE_DEBUG expected 1, got " . Config::MODE_DEBUG;
512 exit(1);
513}
514
515if (Config::MODE_PRODUCTION !== 2) {
516 echo "FAIL: Config::MODE_PRODUCTION expected 2, got " . Config::MODE_PRODUCTION;
517 exit(1);

Callers

nothing calls this directly

Calls 7

setupTestFunction · 0.85
cleanupGeneratedFilesMethod · 0.80
createGoModuleMethod · 0.80
runExtensionInitMethod · 0.80
compileFrankenPHPMethod · 0.80
verifyPHPSymbolsMethod · 0.80

Tested by

no test coverage detected