Skip to content

Commit

Permalink
Merge branch 'master' into bowen/#280-21
Browse files Browse the repository at this point in the history
  • Loading branch information
hwbrzzl authored Nov 17, 2024
2 parents 93ab764 + d1c216d commit fa7f658
Show file tree
Hide file tree
Showing 11 changed files with 575 additions and 18 deletions.
8 changes: 4 additions & 4 deletions contracts/testing/assertable_json.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package testing

type AssertableJSON interface {
Json() map[string]any
Count(key string, value int) AssertableJSON
First(key string, callback func(AssertableJSON)) AssertableJSON
Each(key string, callback func(AssertableJSON)) AssertableJSON
Has(key string) AssertableJSON
HasAll(keys []string) AssertableJSON
HasAny(keys []string) AssertableJSON
HasWithScope(key string, length int, callback func(AssertableJSON)) AssertableJSON
Json() map[string]any
Missing(key string) AssertableJSON
MissingAll(keys []string) AssertableJSON
Where(key string, value any) AssertableJSON
WhereNot(key string, value any) AssertableJSON
Each(key string, callback func(AssertableJSON)) AssertableJSON
First(key string, callback func(AssertableJSON)) AssertableJSON
HasWithScope(key string, length int, callback func(AssertableJSON)) AssertableJSON
}
1 change: 1 addition & 0 deletions contracts/testing/test_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type TestRequest interface {
WithToken(token string, ttype ...string) TestRequest
WithBasicAuth(username, password string) TestRequest
WithoutToken() TestRequest
WithSession(attributes map[string]any) TestRequest
Get(uri string) (TestResponse, error)
Post(uri string, body io.Reader) (TestResponse, error)
Put(uri string, body io.Reader) (TestResponse, error)
Expand Down
11 changes: 9 additions & 2 deletions contracts/testing/test_response.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package testing

import "net/http"

type TestResponse interface {
IsSuccessful() bool
IsServerError() bool
Content() (string, error)
Cookie(name string) *http.Cookie
Cookies() []*http.Cookie
Headers() http.Header
IsServerError() bool
IsSuccessful() bool
Json() (map[string]any, error)
Session() (map[string]any, error)

AssertStatus(status int) TestResponse
AssertOk() TestResponse
AssertCreated() TestResponse
Expand Down
1 change: 1 addition & 0 deletions errors/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var (
StorageFacadeNotSet = New("storage facade is not initialized")
InvalidHttpContext = New("invalid http context")
RouteFacadeNotSet = New("route facade is not initialized")
SessionFacadeNotSet = New("session facade is not initialized")

AuthEmptySecret = New("authentication secret is missing or required")
AuthInvalidClaims = New("authentication token contains invalid claims")
Expand Down
48 changes: 48 additions & 0 deletions mocks/testing/TestRequest.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

201 changes: 201 additions & 0 deletions mocks/testing/TestResponse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions testing/service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
contractsconsole "github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/foundation"
contractsroute "github.com/goravel/framework/contracts/route"
contractsession "github.com/goravel/framework/contracts/session"
"github.com/goravel/framework/errors"
"github.com/goravel/framework/support/color"
)
Expand All @@ -12,6 +13,7 @@ const Binding = "goravel.testing"

var artisanFacade contractsconsole.Artisan
var routeFacade contractsroute.Route
var sessionFacade contractsession.Manager

type ServiceProvider struct {
}
Expand All @@ -32,4 +34,9 @@ func (receiver *ServiceProvider) Boot(app foundation.Application) {
if routeFacade == nil {
color.Errorln(errors.RouteFacadeNotSet.SetModule(errors.ModuleTesting))
}

sessionFacade = app.MakeSession()
if sessionFacade == nil {
color.Errorln(errors.SessionFacadeNotSet.SetModule(errors.ModuleTesting))
}
}
Loading

0 comments on commit fa7f658

Please sign in to comment.